Skip to content

Commit

Permalink
C-c C-b tf: Toggle focus rocket for test.
Browse files Browse the repository at this point in the history
  • Loading branch information
magnars committed Jun 16, 2012
1 parent bf7fd38 commit f5af5d3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ with [Buster.js](http://busterjs.org).
All keybindings in buster-mode start with `C-c C-b` and then a two-letter mnemonic shortcut.

* `td`: toggle-deferred will toggle // in the name of the current test.
* `tf`: toggle-focus-rocket will toggle => in the name of the current test.

## Development

Expand Down
20 changes: 15 additions & 5 deletions buster-mode.el
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
(defun buster-goto-current-test ()
(search-backward-regexp "[\"'][^ ]* .+[\"']: function" nil t))

(defun buster-toggle-deffered ()
(interactive)
(defun buster-toggle-test-name-prefix (prefix)
(save-excursion
(buster-goto-current-test)
(forward-char 1)
(if (looking-at "//")
(delete-char 2)
(insert "//"))))
(if (not (looking-at prefix))
(insert prefix " ")
(delete-char (length prefix))
(while (looking-at " ") (delete-char 1)))))

(defun buster-toggle-deffered ()
(interactive)
(buster-toggle-test-name-prefix "//"))

(defun buster-toggle-focus-rocket ()
(interactive)
(buster-toggle-test-name-prefix "=>"))

(defvar buster-mode-map (make-sparse-keymap)
"buster-mode keymap")

(define-key buster-mode-map
(kbd "C-c C-b td") 'buster-toggle-deffered)
(define-key buster-mode-map
(kbd "C-c C-b tf") 'buster-toggle-focus-rocket)

(define-minor-mode buster-mode
"Buster mode"
Expand Down
10 changes: 5 additions & 5 deletions features/toggle-deferred.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Toggle deferred
"""
And I go to the front of the word "assert"
And I press "C-c C-b td"
Then I should not see "//contains"
Then I should not see "// contains"

Scenario: Deferring a test
When I insert:
Expand All @@ -25,22 +25,22 @@ Feature: Toggle deferred
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b td"
Then I should see "//contains"
Then I should see "// contains"
And the cursor should be before "assert"

Scenario: Undeferring a test
When I insert:
"""
buster.testCase('Building Page', {
"//contains title after loading page": function () {
"// contains title after loading page": function () {
assert.match(document.body.innerHTML, "Zombie TDD");
}
});
"""
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b td"
Then I should not see "//contains"
Then I should not see "// contains"

Scenario: Deferring a single quoted test
When I insert:
Expand All @@ -54,4 +54,4 @@ Feature: Toggle deferred
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b td"
Then I should see "'//contains"
Then I should see "'// contains"
43 changes: 43 additions & 0 deletions features/toggle-focus-rocket.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Feature: Toggle focus rocket

Scenario: Focus test
When I insert:
"""
buster.testCase('Building Page', {
"contains title after loading page": function () {
assert.match(document.body.innerHTML, "Zombie TDD");
}
});
"""
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b tf"
Then I should see "=> contains"

Scenario: Blur test
When I insert:
"""
buster.testCase('Building Page', {
"=> contains title after loading page": function () {
assert.match(document.body.innerHTML, "Zombie TDD");
}
});
"""
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b tf"
Then I should not see "=> contains"

Scenario: Blur test even when user hasn't added a space at the end
When I insert:
"""
buster.testCase('Building Page', {
"=>contains title after loading page": function () {
assert.match(document.body.innerHTML, "Zombie TDD");
}
});
"""
And I turn on buster-mode
And I go to the front of the word "assert"
And I press "C-c C-b tf"
Then I should not see "=>contains"

0 comments on commit f5af5d3

Please sign in to comment.