├── .editorconfig ├── .gitignore ├── .jscsrc ├── .jshintrc ├── .travis.yml ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── Default.sublime-commands ├── Gruntfile.js ├── Jasmine_BDD.sublime-settings ├── Main.sublime-menu ├── README.md ├── img ├── demo.gif ├── logo.png └── logo.sketch │ ├── Data │ ├── QuickLook │ ├── Preview.png │ └── Thumbnail.png │ ├── metadata │ └── version ├── jasmine_commands.py ├── messages.json ├── messages └── 0.1.md ├── package.json └── snippets ├── afterEach.sublime-snippet ├── beforeEach.sublime-snippet ├── calls.all.sublime-snippet ├── calls.allArgs.sublime-snippet ├── calls.any.sublime-snippet ├── calls.argsFor.sublime-snippet ├── calls.count.sublime-snippet ├── calls.first.sublime-snippet ├── calls.mostRecent.sublime-snippet ├── calls.reset.sublime-snippet ├── createSpy.sublime-snippet ├── createSpyObj.sublime-snippet ├── describe.sublime-snippet ├── expect.sublime-snippet ├── it.sublime-snippet ├── jasmine.any.sublime-snippet ├── jasmine.objectContaining.sublime-snippet ├── not.toBe.sublime-snippet ├── not.toBeCloseTo.sublime-snippet ├── not.toBeDefined.sublime-snippet ├── not.toBeFalsy.sublime-snippet ├── not.toBeGreaterThan.sublime-snippet ├── not.toBeLessThan.sublime-snippet ├── not.toBeNull.sublime-snippet ├── not.toBeTruthy.sublime-snippet ├── not.toBeUndefined.sublime-snippet ├── not.toContain.sublime-snippet ├── not.toEqual.sublime-snippet ├── not.toMatch.sublime-snippet ├── not.toThrow.sublime-snippet ├── spyOn.and.callThrough.sublime-snippet ├── spyOn.and.returnValue.sublime-snippet ├── spyOn.and.stub.sublime-snippet ├── spyOn.and.throwError.sublime-snippet ├── spyOn.sublime-snippet ├── toBe.sublime-snippet ├── toBeCloseTo.sublime-snippet ├── toBeDefined.sublime-snippet ├── toBeFalsy.sublime-snippet ├── toBeGreatherThan.sublime-snippet ├── toBeLessThan.sublime-snippet ├── toBeNull.sublime-snippet ├── toBeTruthy.sublime-snippet ├── toBeUndefined.sublime-snippet ├── toContain.sublime-snippet ├── toEqual.sublime-snippet ├── toHaveBeenCalled.sublime-snippet ├── toHaveBeenCalledWith.sublime-snippet ├── toMatch.sublime-snippet ├── toThrow.sublime-snippet ├── xdescribe.sublime-snippet └── xit.sublime-snippet /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 2 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | 15 | [*.sublime-snippet] 16 | indent_style = tab 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": [ 3 | "for", 4 | "while", 5 | "do", 6 | "try", 7 | "catch", 8 | "case", 9 | "default" 10 | ], 11 | "requireSpaceAfterKeywords": [ 12 | "if", 13 | "else", 14 | "for", 15 | "while", 16 | "do", 17 | "switch", 18 | "return", 19 | "try", 20 | "catch" 21 | ], 22 | "requireSpaceBeforeBlockStatements": true, 23 | "requireParenthesesAroundIIFE": true, 24 | "requireSpacesInConditionalExpression": { 25 | "afterTest": true, 26 | "beforeConsequent": true, 27 | "afterConsequent": true, 28 | "beforeAlternate": true 29 | }, 30 | "requireSpacesInFunctionExpression": { 31 | "beforeOpeningRoundBrace": false, 32 | "beforeOpeningCurlyBrace": true 33 | }, 34 | "disallowSpacesInFunctionExpression": { 35 | "beforeOpeningRoundBrace": true, 36 | "beforeOpeningCurlyBrace": false 37 | }, 38 | "requireSpacesInAnonymousFunctionExpression": { 39 | "beforeOpeningRoundBrace": false, 40 | "beforeOpeningCurlyBrace": true 41 | }, 42 | "disallowSpacesInAnonymousFunctionExpression": { 43 | "beforeOpeningRoundBrace": true, 44 | "beforeOpeningCurlyBrace": false 45 | }, 46 | "requireSpacesInNamedFunctionExpression": { 47 | "beforeOpeningRoundBrace": false, 48 | "beforeOpeningCurlyBrace": true 49 | }, 50 | "disallowSpacesInNamedFunctionExpression": { 51 | "beforeOpeningRoundBrace": true, 52 | "beforeOpeningCurlyBrace": false 53 | }, 54 | "requireSpacesInFunctionDeclaration": { 55 | "beforeOpeningRoundBrace": false, 56 | "beforeOpeningCurlyBrace": true 57 | }, 58 | "disallowSpacesInFunctionDeclaration": { 59 | "beforeOpeningRoundBrace": true, 60 | "beforeOpeningCurlyBrace": false 61 | }, 62 | "disallowMultipleVarDecl": true, 63 | "requireBlocksOnNewline": true, 64 | "disallowPaddingNewlinesInBlocks": true, 65 | "disallowEmptyBlocks": true, 66 | "disallowSpacesInsideObjectBrackets": "nested", 67 | "disallowSpacesInsideArrayBrackets": "nested", 68 | "disallowSpacesInsideParentheses": true, 69 | "disallowSpaceAfterObjectKeys": true, 70 | "requireCommaBeforeLineBreak": true, 71 | "requireOperatorBeforeLineBreak": [ 72 | "?", 73 | "=", 74 | "+", 75 | "-", 76 | "/", 77 | "*", 78 | "==", 79 | "===", 80 | "!=", 81 | "!==", 82 | ">", 83 | ">=", 84 | "<", 85 | "<=" 86 | ], 87 | "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], 88 | "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], 89 | "requireSpaceBeforeBinaryOperators": [ 90 | "=", 91 | ",", 92 | "+", 93 | "-", 94 | "/", 95 | "*", 96 | "==", 97 | "===", 98 | "!=", 99 | "!==" 100 | ], 101 | "requireSpaceAfterBinaryOperators": [ 102 | "=", 103 | ",", 104 | "+", 105 | "-", 106 | "/", 107 | "*", 108 | "==", 109 | "===", 110 | "!=", 111 | "!==" 112 | ], 113 | "requireCamelCaseOrUpperCaseIdentifiers": true, 114 | "disallowKeywords": ["with"], 115 | "disallowMultipleLineStrings": true, 116 | "disallowMultipleLineBreaks": true, 117 | "validateLineBreaks": "LF", 118 | "validateQuoteMarks": "\"", 119 | "validateIndentation": "2", 120 | "disallowMixedSpacesAndTabs": true, 121 | "disallowTrailingWhitespace": true, 122 | "disallowTrailingComma": true, 123 | "disallowKeywordsOnNewLine": ["else"], 124 | "requireLineFeedAtFileEnd": true, 125 | "maximumLineLength": 120, 126 | "requireCapitalizedConstructors": true, 127 | "safeContextKeyword": ["self"], 128 | "requireDotNotation": true, 129 | "disallowYodaConditions": true, 130 | "validateJSDoc": { 131 | "checkParamNames": true, 132 | "checkRedundantParams": true, 133 | "requireParamTypes": true 134 | }, 135 | "requireSpaceAfterLineComment": true 136 | } 137 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase" : true 3 | , "curly" : true 4 | , "eqeqeq" : true 5 | , "forin" : true 6 | , "immed" : true 7 | , "indent" : 2 8 | , "latedef" : true 9 | , "newcap" : true 10 | , "noarg" : true 11 | , "noempty" : true 12 | , "nonew" : true 13 | , "plusplus" : true 14 | , "quotmark" : "double" 15 | , "undef" : true 16 | , "unused" : true 17 | , "strict" : true 18 | , "trailing" : true 19 | , "maxparams" : 3 20 | , "maxlen" : 80 21 | , "asi" : true 22 | , "laxcomma" : true 23 | , "white" : true 24 | } 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 4 | before_script: 5 | - npm install -g grunt-cli 6 | -------------------------------------------------------------------------------- /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+period"], 4 | "command": "jasmine_toggle", 5 | "args": {"split_view": false}, 6 | "context": [{ 7 | "key": "selector", "operator": "equal", 8 | "operand": "source.js, source.spec.js" 9 | }] 10 | }, 11 | 12 | // Split view 13 | { 14 | "keys": ["ctrl+alt+period"], 15 | "command": "jasmine_toggle", 16 | "args": {"split_view": true}, 17 | "context": [{ 18 | "key": "selector", "operator": "equal", 19 | "operand": "source.js, source.spec.js" 20 | }] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["super+period"], 4 | "command": "jasmine_toggle", 5 | "args": {"split_view": false}, 6 | "context": [{ 7 | "key": "selector", "operator": "equal", 8 | "operand": "source.js, source.spec.js" 9 | }] 10 | }, 11 | 12 | // Split view 13 | { 14 | "keys": ["super+ctrl+period"], 15 | "command": "jasmine_toggle", 16 | "args": {"split_view": true}, 17 | "context": [{ 18 | "key": "selector", "operator": "equal", 19 | "operand": "source.js, source.spec.js" 20 | }] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+period"], 4 | "command": "jasmine_toggle", 5 | "args": {"split_view": false}, 6 | "context": [{ 7 | "key": "selector", "operator": "equal", 8 | "operand": "source.js, source.spec.js" 9 | }] 10 | }, 11 | 12 | // Split view 13 | { 14 | "keys": ["ctrl+alt+period"], 15 | "command": "jasmine_toggle", 16 | "args": {"split_view": true}, 17 | "context": [{ 18 | "key": "selector", "operator": "equal", 19 | "operand": "source.js, source.spec.js" 20 | }] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Jasmine BDD: Switch between code and spec", 4 | "command": "jasmine_toggle", 5 | "args": { "split_view": false } 6 | }, 7 | { 8 | "caption": "Jasmine BDD: Create spec file", 9 | "command": "jasmine_create_spec", 10 | "args": { "split_view": false } 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* global module */ 2 | module.exports = function(grunt) { 3 | "use strict"; 4 | 5 | grunt.loadNpmTasks("grunt-lintspaces") 6 | grunt.loadNpmTasks("grunt-bump") 7 | 8 | grunt.initConfig({ 9 | lintspaces: { 10 | all: { 11 | src: ["*"], 12 | options: { 13 | editorconfig: ".editorconfig" 14 | } 15 | } 16 | }, 17 | bump: { 18 | options: { 19 | pushTo: "origin", 20 | tagName: "%VERSION%" 21 | } 22 | } 23 | }) 24 | 25 | grunt.registerTask("test", ["lintspaces"]) 26 | } 27 | -------------------------------------------------------------------------------- /Jasmine_BDD.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Ignore directories when searching for files (source and specs) 3 | "ignored_directories": [".git", "vendor", "tmp", "node_modules"], 4 | 5 | // The parent folder name for the spec files 6 | "jasmine_path": "spec" 7 | } 8 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption":"Preferences", 4 | "mnemonic":"n", 5 | "id":"preferences", 6 | "children":[ 7 | { 8 | "caption":"Package Settings", 9 | "mnemonic":"P", 10 | "id":"package-settings", 11 | "children":[ 12 | { 13 | "caption":"Jasmine BDD", 14 | "children":[ 15 | // Settings 16 | { 17 | "command":"open_file", 18 | "args":{ 19 | "file":"${packages}/Jasmine BDD/Jasmine_BDD.sublime-settings" 20 | }, 21 | "caption":"Settings – Default" 22 | }, 23 | { 24 | "command":"open_file", 25 | "args":{ 26 | "file":"${packages}/User/Jasmine_BDD.sublime-settings" 27 | }, 28 | "caption":"Settings – User" 29 | }, 30 | { 31 | "caption":"-" 32 | }, 33 | // Keybindings - Default 34 | { 35 | "command": "open_file", 36 | "args": { 37 | "file": "${packages}/Jasmine BDD/Default (OSX).sublime-keymap", 38 | "platform": "OSX" 39 | }, 40 | "caption": "Key Bindings – Default" 41 | }, 42 | { 43 | "command": "open_file", 44 | "args": { 45 | "file": "${packages}/Jasmine BDD/Default (Linux).sublime-keymap", 46 | "platform": "Linux" 47 | }, 48 | "caption": "Key Bindings – Default" 49 | }, 50 | { 51 | "command": "open_file", 52 | "args": { 53 | "file": "${packages}/Jasmine BDD/Default (Windows).sublime-keymap", 54 | "platform": "Windows" 55 | }, 56 | "caption": "Key Bindings – Default" 57 | }, 58 | // Keybindings - User 59 | { 60 | "command": "open_file", 61 | "args": { 62 | "file": "${packages}/User/Default (OSX).sublime-keymap", 63 | "platform": "OSX" 64 | }, 65 | "caption": "Key Bindings – User" 66 | }, 67 | { 68 | "command": "open_file", 69 | "args": { 70 | "file": "${packages}/User/Default (Linux).sublime-keymap", 71 | "platform": "Linux" 72 | }, 73 | "caption": "Key Bindings – User" 74 | }, 75 | { 76 | "command": "open_file", 77 | "args": { 78 | "file": "${packages}/User/Default (Windows).sublime-keymap", 79 | "platform": "Windows" 80 | }, 81 | "caption": "Key Bindings – User" 82 | } 83 | ] 84 | } 85 | ] 86 | } 87 | ] 88 | } 89 | ] 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jasmine snippets [![Build Status](https://api.travis-ci.org/caiogondim/jasmine-sublime-snippets.png?branch=master)](https://travis-ci.org/caiogondim/jasmine-sublime-snippets) 2 | 3 | Jasmine snippets logo 4 | 5 | Jasmine is a behavior-driven development framework for testing JavaScript code. 6 | It does not depend on any other JavaScript frameworks. It does not require a 7 | DOM. And it has a clean, obvious syntax so that you can easily write tests. This 8 | package is for Jasmine **version 2.0.0**. 9 | 10 | To install through Package Control, search for **Jasmine**. If you 11 | still don't have Package Control in Sublime Text, go get it. If you insist to 12 | not install it, you can download the package and put it manually inside your 13 | Pacakages directory. It should work but will not update automatically. 14 | 15 | 16 | ## Demo 17 | 18 | Some of the snippets in the wild. 19 | 20 | ![](https://raw.github.com/caiogondim/jasmine-sublime-snippets/master/img/demo.gif) 21 | 22 | 23 | ## Snippets 24 | 25 | Below is a list of all snippets currently supported on this package and the 26 | triggers of each one. The **⇥** means the `TAB` key. 27 | 28 | ### Specs 29 | - `describe`: desc⇥ 30 | - `xdescribe`: xdesc⇥ 31 | - `it`: it⇥ 32 | - `xit`: xit⇥ 33 | - `afterEach`: ae⇥ 34 | - `beforeEach`: be⇥ 35 | 36 | ### Expectations 37 | - `expect`: exp⇥ 38 | - `expect().toBe`: tb⇥ 39 | - `expect().toBeCloseTo`: tbct⇥ 40 | - `expect().toBeDefined`: tbd⇥ 41 | - `expect().toBeFalsy`: tbf⇥ 42 | - `expect().toBeGreaterThan`: tbgt⇥ 43 | - `expect().toBeLessThan`: tblt⇥ 44 | - `expect().toBeNull`: tbn⇥ 45 | - `expect().toBeTruthy`: tbt⇥ 46 | - `expect().toBeUndefined`: tbu⇥ 47 | - `expect().toContain`: tc⇥ 48 | - `expect().toEqual`: te⇥ 49 | - `expect().toHaveBeenCalled`: thbc⇥ 50 | - `expect().toHaveBeenCalledWith`: thbcw⇥ 51 | - `expect().toMatch`: tm⇥ 52 | - `expect().toThrow`: tt⇥ 53 | - `expect().not.toBe`: nb⇥ 54 | - `expect().not.toBeCloseTo`: nct⇥ 55 | - `expect().not.toBeDefined`: nd⇥ 56 | - `expect().not.toBeFalsy`: nf⇥ 57 | - `expect().not.toBeGreaterThan`: ngt⇥ 58 | - `expect().not.toBeLessThan`: nlt⇥ 59 | - `expect().not.toBeNull`: nn⇥ 60 | - `expect().not.toBeTruthy`: nt⇥ 61 | - `expect().not.toBeUndefined`: nu⇥ 62 | - `expect().not.toContain`: nc⇥ 63 | - `expect().not.toEqual`: ne⇥ 64 | - `expect().not.toMatch`: nm⇥ 65 | - `expect().not.toThrow`: nt⇥ 66 | - `jasmine.any`: a⇥ 67 | - `jasmine.objectContaining`: oc⇥ 68 | 69 | ### Spies 70 | - `spyOn`: s⇥ 71 | - `spyOn.and.callThrough`: sct⇥ 72 | - `spyOn.and.returnValue`: srv⇥ 73 | - `spyOn.and.stub`: ss⇥ 74 | - `spyOn.and.throwError`: se⇥ 75 | - `spy.calls.all`: ca⇥ 76 | - `spy.calls.allArgs`: caa⇥ 77 | - `spy.calls.any`: ca⇥ 78 | - `spy.calls.argsFor`: caf⇥ 79 | - `spy.calls.count`: cc⇥ 80 | - `spy.calls.first`: cf⇥ 81 | - `spy.calls.mostRecent`: cmr⇥ 82 | - `spy.calls.reset`: cr⇥ 83 | - `createSpy`: cs⇥ 84 | - `createSpyObj`: cso⇥ 85 | 86 | 87 | ## Commands 88 | 89 | ### Toggle between code and spec 90 | 91 | This command will open the spec or source file that has the same path of the 92 | active view file. If you're looking at a source file and the package can't find 93 | any specs, it'll display a list of possible directories to create a new one. 94 | 95 | To run this command, you can use `ctrl+.` or `ctrl+shift+.` (this last one will 96 | toggle using a split view), or select `Jasmine BDD: Switch between code and 97 | spec`. 98 | 99 | ### Create spec file 100 | 101 | This command is exactly the same as running `toggle` and not finding specs. It 102 | doesn't have a key binding, but you can use `jasmine_create_spec` as a command 103 | name, like this: 104 | 105 | `{ "keys": ["KEYS"], "command": "jasmine_create_spec", "args": { "split_view": false } }` 106 | 107 | 108 | ### Command Settings 109 | 110 | There are two possible settings: 111 | ```javascript 112 | { 113 | // Ignore directories when searching for files (source and specs) 114 | "ignored_directories": [".git", "vendor", "tmp", "node_modules"], 115 | 116 | // The parent folder name for the spec files 117 | "jasmine_path": "spec" 118 | } 119 | ``` 120 | 121 | 122 | ## Contributing 123 | 124 | * Fork this repository 125 | * Run `npm install` 126 | * Create a new branch for each feature or improvement 127 | * Ensure that your code is accompanied with tests 128 | * Run `grunt test` to ensure that your new tests and the old ones are all passing 129 | * Send a pull request from each feature branch 130 | 131 | If you're on a OS X machine, you can run `npm run-script symlink` to symlink 132 | this package directly to 133 | `~/Library/Application\ Support/Sublime\ Text\ 3/Packages/jasmine-snippets` 134 | and see the changes everytime you save a file. 135 | 136 | ### Contributors 137 | 138 | - [Nicolás Santángelo](https://github.com/NicoSantangelo) 139 | - [Breno Polanski](https://github.com/brenopolanski) 140 | - [Jesse Atkinson](https://github.com/jsatk) 141 | 142 | 143 | ## License 144 | The MIT License (MIT) 145 | 146 | Copyright (c) 2014 [Caio Gondim](http://caiogondim.com) 147 | 148 | Permission is hereby granted, free of charge, to any person obtaining a copy 149 | of this software and associated documentation files (the "Software"), to deal 150 | in the Software without restriction, including without limitation the rights 151 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 152 | copies of the Software, and to permit persons to whom the Software is 153 | furnished to do so, subject to the following conditions: 154 | 155 | The above copyright notice and this permission notice shall be included in all 156 | copies or substantial portions of the Software. 157 | 158 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 159 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 160 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 161 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 162 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 163 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 164 | SOFTWARE. 165 | -------------------------------------------------------------------------------- /img/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiogondim/jasmine-sublime-snippets/1db759b977aa80e48f1502228a7b304db612b174/img/demo.gif -------------------------------------------------------------------------------- /img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiogondim/jasmine-sublime-snippets/1db759b977aa80e48f1502228a7b304db612b174/img/logo.png -------------------------------------------------------------------------------- /img/logo.sketch/Data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiogondim/jasmine-sublime-snippets/1db759b977aa80e48f1502228a7b304db612b174/img/logo.sketch/Data -------------------------------------------------------------------------------- /img/logo.sketch/QuickLook/Preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiogondim/jasmine-sublime-snippets/1db759b977aa80e48f1502228a7b304db612b174/img/logo.sketch/QuickLook/Preview.png -------------------------------------------------------------------------------- /img/logo.sketch/QuickLook/Thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiogondim/jasmine-sublime-snippets/1db759b977aa80e48f1502228a7b304db612b174/img/logo.sketch/QuickLook/Thumbnail.png -------------------------------------------------------------------------------- /img/logo.sketch/metadata: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | app 6 | com.bohemiancoding.sketch 7 | build 8 | 5361 9 | commit 10 | 4570185e2c9ded14ebc287c802202c126573b527 11 | fonts 12 | 13 | length 14 | 33479 15 | version 16 | 18 17 | 18 | 19 | -------------------------------------------------------------------------------- /img/logo.sketch/version: -------------------------------------------------------------------------------- 1 | 18 -------------------------------------------------------------------------------- /jasmine_commands.py: -------------------------------------------------------------------------------- 1 | # Huge thanks to RubyTests( https://github.com/maltize/sublime-text-2-ruby-tests ) 2 | import sublime, sublime_plugin 3 | import re 4 | import os 5 | import functools 6 | 7 | class BaseCommand(sublime_plugin.TextCommand): 8 | def run(self, edit, split_view = False): 9 | self.load_settings() 10 | self.create_base_spec_folder() 11 | self.split_view = split_view 12 | self._run(edit) 13 | 14 | def load_settings(self): 15 | settings = sublime.load_settings("Jasmine_BDD.sublime-settings") 16 | self.ignored_directories = settings.get("ignored_directories", []) 17 | self.jasmine_path = settings.get("jasmine_path", "spec") 18 | 19 | def create_base_spec_folder(self): 20 | base, _ = os.path.split(self.view.file_name()) 21 | for folder in self.window().folders(): 22 | spec_path = os.path.join(folder, self.jasmine_path) 23 | if re.search(folder, base) and not os.path.exists(spec_path): 24 | os.mkdir(spec_path) 25 | 26 | def window(self): 27 | return self.view.window() 28 | 29 | class JasmineToggleCommand(BaseCommand): 30 | def _run(self, edit): 31 | file_type = self.file_type() 32 | if not file_type: 33 | return 34 | 35 | alternates = self.reduce_alternatives(file_type) 36 | if alternates: 37 | self.show_alternatives(alternates) 38 | else: 39 | SpecFileInterface(self).interact() 40 | 41 | def reduce_alternatives(self, file_type): 42 | alternates = self.project_files(lambda file: file in file_type.possible_alternate_files()) 43 | for alternate in alternates: 44 | if re.search(file_type.parent_dir_name(), alternate): 45 | alternates = [alternate] 46 | break 47 | return alternates 48 | 49 | def show_alternatives(self, alternates): 50 | if self.split_view: 51 | ShowPanels(self.window()).split() 52 | if len(alternates) == 1: 53 | self.window().open_file(alternates.pop()) 54 | else: 55 | callback = functools.partial(self.on_selected, alternates) 56 | self.window().show_quick_panel(alternates, callback) 57 | 58 | def file_type(self): 59 | file_name = self.view.file_name() 60 | if JasmineFile.test(file_name): 61 | return JasmineFile(file_name) 62 | elif JSFile.test(file_name): 63 | return JSFile(file_name) 64 | 65 | def on_selected(self, alternates, index): 66 | if index == -1: 67 | return 68 | self.window().open_file(alternates[index]) 69 | 70 | def project_files(self, file_matcher): 71 | directories = self.window().folders() 72 | return [os.path.join(dirname, file) for directory in directories for dirname, _, files in self.walk(directory) for file in filter(file_matcher, files)] 73 | 74 | def walk(self, directory): 75 | for dir, dirnames, files in os.walk(directory): 76 | dirnames[:] = [dirname for dirname in dirnames if dirname not in self.ignored_directories] 77 | yield dir, dirnames, files 78 | 79 | class JasmineCreateSpecCommand(BaseCommand): 80 | def _run(self, edit): 81 | SpecFileInterface(self).interact() 82 | 83 | ## 84 | # Classes 85 | ## 86 | 87 | class ShowPanels(): 88 | def __init__(self, window): 89 | self.window = window 90 | 91 | def split(self): 92 | self.window.run_command('set_layout', { 93 | "cols": [0.0, 0.5, 1.0], 94 | "rows": [0.0, 1.0], 95 | "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] 96 | }) 97 | self.window.focus_group(1) 98 | 99 | class BaseFile(): 100 | def __init__(self, file_name): 101 | self.folder_name, self.file_name = os.path.split(file_name) 102 | self.absolute_path = file_name 103 | 104 | def parent_dir_name(self): 105 | head_dir, tail_dir = os.path.split(self.folder_name) 106 | return tail_dir 107 | 108 | class JSFile(BaseFile): 109 | def possible_alternate_files(self): 110 | return [ 111 | self.file_name.replace(".js", "_spec.js"), 112 | self.file_name.replace(".js", ".spec.js") 113 | ] 114 | 115 | @classmethod 116 | def test(cls, file_name): 117 | return re.search('\w+\.js', file_name) 118 | 119 | class JasmineFile(BaseFile): 120 | def possible_alternate_files(self): 121 | possible_set = set([self.file_name.replace("_spec.js", ".js"), self.file_name.replace(".spec.js", ".js")]) 122 | file_name_set = set([self.file_name]) 123 | return list(possible_set - file_name_set) 124 | 125 | @classmethod 126 | def test(cls, file_name): 127 | return re.search('\w+\.spec.js', file_name) or re.search('\w+\_spec.js', file_name) 128 | 129 | class SpecFileInterface(): 130 | relative_paths = [] 131 | full_torelative_paths = {} 132 | rel_path_start = 0 133 | 134 | def __init__(self, command): 135 | self.ignored_directories = command.ignored_directories 136 | self.jasmine_path = command.jasmine_path 137 | self.window = command.window() 138 | self.current_file = command.view.file_name() 139 | self.split_view = command.split_view 140 | 141 | def interact(self): 142 | self.build_relative_paths() 143 | self.window.show_quick_panel(self.relative_paths, self.dir_selected) 144 | 145 | def build_relative_paths(self): 146 | folders = self.active_project(self.window.folders()) 147 | self.relative_paths = [] 148 | self.full_torelative_paths = {} 149 | for path in folders: 150 | rootfolders = os.path.split(path)[-1] 151 | self.rel_path_start = len(os.path.split(path)[0]) + 1 152 | self.add_path(rootfolders, path) 153 | self.walk_dir_paths(path) 154 | 155 | def add_path(self, path_key, path_value): 156 | if self.is_valid_path(path_key) and self.is_valid_path(path_value): 157 | self.full_torelative_paths[path_key] = path_value 158 | self.relative_paths.append(path_key) 159 | 160 | def walk_dir_paths(self, path): 161 | for base, dirs, files in os.walk(path): 162 | self.remove_ignored_directories(dirs) 163 | for dir in dirs: 164 | dir_path = os.path.join(base, dir) 165 | relative_path = dir_path[self.rel_path_start:] 166 | self.add_path(relative_path, dir_path) 167 | 168 | def remove_ignored_directories(self, dirs): 169 | for ignored_dir in self.ignored_directories: 170 | if ignored_dir in dirs: 171 | dirs.remove(ignored_dir) 172 | 173 | def active_project(self, folders): 174 | for folder in folders: 175 | project_name = os.path.split(folder)[-1] 176 | if re.search(project_name, self.current_file): 177 | return [folder] 178 | return folders 179 | 180 | def is_valid_path(self, path): 181 | if not re.search(self.jasmine_path, self.current_file): 182 | return re.search(self.jasmine_path, path) 183 | return True 184 | 185 | def dir_selected(self, selected_index): 186 | if selected_index != -1: 187 | self.selected_dir = self.relative_paths[selected_index] 188 | self.selected_dir = self.full_torelative_paths[self.selected_dir] 189 | self.window.show_input_panel("File name", self.suggest_file_name(self.selected_dir), self.file_name_input, None, None) 190 | 191 | def suggest_file_name(self, path): 192 | current_file = os.path.split(self.current_file)[-1] 193 | return self.set_file_name(path, current_file) 194 | 195 | def set_file_name(self, path, current_file): 196 | if re.search(self.jasmine_path, self.current_file): 197 | return re.sub('.spec.js|_spec.js', '.js', current_file) 198 | else: 199 | return current_file.replace('.js', '.spec.js') 200 | 201 | def file_name_input(self, file_name): 202 | full_path = os.path.join(self.selected_dir, file_name) 203 | 204 | if os.path.lexists(full_path): 205 | self.window.open_file(full_path) 206 | return 207 | else: 208 | self.create_and_open_file(full_path) 209 | 210 | def create_and_open_file(self, path): 211 | if not os.path.exists(path): 212 | self.create_folders(path) 213 | 214 | if self.split_view: 215 | ShowPanels(self.window).split() 216 | 217 | with open(path, 'w') as f: 218 | f.write("") 219 | 220 | view = self.window.open_file(path) 221 | sublime.set_timeout(lambda: view.run_command("insert_snippet", { "name": "Packages/Jasmine BDD/snippets/describe.sublime-snippet" }), 0) 222 | 223 | def create_folders(self, filename): 224 | base, filename = os.path.split(filename) 225 | if not os.path.exists(base): 226 | parent = os.path.split(base)[0] 227 | if not os.path.exists(parent): 228 | self.create_folders(parent) 229 | os.mkdir(base) 230 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "0.1": "messages/0.1.md" 3 | } 4 | -------------------------------------------------------------------------------- /messages/0.1.md: -------------------------------------------------------------------------------- 1 | # Jasmine snippets 0.1 2 | 3 | You can now create a spec from the current JS file using the `ctrl + .` or 4 | `ctrl+ shift + .` keys. Huge thanks to @NicoSantangelo. 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-jasmine-sublime-snippets", 3 | "version": "0.1.1", 4 | "description": "Jasmine snippets for Sublime Text", 5 | "main": "grunt", 6 | "dependencies": { 7 | "grunt": "~0.4.2" 8 | }, 9 | "devDependencies": { 10 | "grunt": "~0.4.5", 11 | "grunt-lintspaces": "~0.3.1", 12 | "grunt-bump": "0.0.14" 13 | }, 14 | "scripts": { 15 | "test": "grunt test", 16 | "symlink": "ln -sF `pwd` ~/Library/Application\\ Support/Sublime\\ Text\\ 3/Packages/jasmine-snippets" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/caiogondim/js-jasmine-sublime-snippets.git" 21 | }, 22 | "keywords": [ 23 | "javascript", 24 | "sublime", 25 | "text", 26 | "snippets", 27 | "jasmine" 28 | ], 29 | "author": "Caio Gondim", 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/caiogondim/js-jasmine-sublime-snippets/issues" 33 | }, 34 | "homepage": "https://github.com/caiogondim/js-jasmine-sublime-snippets" 35 | } 36 | -------------------------------------------------------------------------------- /snippets/afterEach.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | afterEach 10 | 11 | -------------------------------------------------------------------------------- /snippets/beforeEach.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | beforeEach 10 | 11 | -------------------------------------------------------------------------------- /snippets/calls.all.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.all 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.allArgs.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.allArgs 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.any.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.any 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.argsFor.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.argsFor 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.count.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.count 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.first.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.first 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.mostRecent.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.mostRecent 7 | 8 | -------------------------------------------------------------------------------- /snippets/calls.reset.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spy.calls.reset 7 | 8 | -------------------------------------------------------------------------------- /snippets/createSpy.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | createSpy 6 | 7 | -------------------------------------------------------------------------------- /snippets/createSpyObj.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | createSpyObj 6 | 7 | -------------------------------------------------------------------------------- /snippets/describe.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | describe 10 | 11 | -------------------------------------------------------------------------------- /snippets/expect.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | expect 6 | 7 | -------------------------------------------------------------------------------- /snippets/it.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | it 10 | 11 | -------------------------------------------------------------------------------- /snippets/jasmine.any.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | jasmine.any 6 | 7 | -------------------------------------------------------------------------------- /snippets/jasmine.objectContaining.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | jasmine.objectContaining 6 | 7 | -------------------------------------------------------------------------------- /snippets/not.toBe.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBe 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeCloseTo.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeCloseTo 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeDefined.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeDefined 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeFalsy.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeFalsy 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeGreaterThan.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeGreaterThan 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeLessThan.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeLessThan 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeNull.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeNull 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeTruthy.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeTruthy 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toBeUndefined.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toBeUndefined 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toContain.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toContain 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toEqual.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toEqual 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toMatch.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toMatch 7 | 8 | -------------------------------------------------------------------------------- /snippets/not.toThrow.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | not.toThrow 7 | 8 | -------------------------------------------------------------------------------- /snippets/spyOn.and.callThrough.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | spyOn.and.callThrough 6 | 7 | -------------------------------------------------------------------------------- /snippets/spyOn.and.returnValue.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | source.js 8 | spyOn.and.callFake 9 | 10 | -------------------------------------------------------------------------------- /snippets/spyOn.and.stub.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | spyOn.and.stub 6 | 7 | -------------------------------------------------------------------------------- /snippets/spyOn.and.throwError.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.js 5 | spyOn.and.callFake 6 | 7 | -------------------------------------------------------------------------------- /snippets/spyOn.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | spyOn 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBe.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBe 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeCloseTo.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeCloseTo 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeDefined.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeDefined 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeFalsy.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeFalsy 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeGreatherThan.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeGreaterThan 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeLessThan.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeLessThan 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeNull.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeNull 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeTruthy.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeTruthy 7 | 8 | -------------------------------------------------------------------------------- /snippets/toBeUndefined.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toBeUndefined 7 | 8 | -------------------------------------------------------------------------------- /snippets/toContain.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toContain 7 | 8 | -------------------------------------------------------------------------------- /snippets/toEqual.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toEqual 7 | 8 | -------------------------------------------------------------------------------- /snippets/toHaveBeenCalled.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toHaveBeenCalled 7 | 8 | -------------------------------------------------------------------------------- /snippets/toHaveBeenCalledWith.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toHaveBeenCalledWith 7 | 8 | -------------------------------------------------------------------------------- /snippets/toMatch.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toMatch 7 | 8 | -------------------------------------------------------------------------------- /snippets/toThrow.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | source.js 6 | toThrow 7 | 8 | -------------------------------------------------------------------------------- /snippets/xdescribe.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | xdescribe 10 | 11 | -------------------------------------------------------------------------------- /snippets/xit.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | source.js 9 | xit 10 | 11 | --------------------------------------------------------------------------------