├── espuds-helpers.el ├── espuds-misc.el ├── README.markdown ├── espuds.el ├── espuds-buffer.el ├── espuds-region.el ├── espuds-input.el ├── espuds-text.el └── espuds-movement.el /espuds-helpers.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-helpers.el --- Helper functions 2 | 3 | 4 | (defun espuds-fake-eval (contents) 5 | "Dump contents to a temp file and then load it." 6 | (let ((file (make-temp-file "ecukes-"))) 7 | (with-temp-file file 8 | (insert contents)) 9 | (load file))) 10 | 11 | (defun espuds-buffer-contents () 12 | "Return all text in current buffer." 13 | (buffer-string)) 14 | 15 | (defun espuds-region () 16 | "Return the text selected by region, if any." 17 | (if mark-active 18 | (buffer-substring-no-properties (region-beginning) (region-end)) 19 | "")) 20 | 21 | (defun espuds-quit () 22 | "Quit without signal." 23 | (flet ((signal (&rest args) nil)) 24 | (keyboard-quit))) 25 | 26 | (provide 'espuds-helpers) 27 | 28 | ;;; espuds-helpers.el ends here 29 | -------------------------------------------------------------------------------- /espuds-misc.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-misc.el --- Definitions that don't fit in any other file 2 | 3 | ;; Turns on some mode. 4 | ;; 5 | ;; Usage: 6 | ;; When I turn on ruby-mode 7 | (When "^I turn on \\(.+\\)$" 8 | (lambda (mode) 9 | (let ((v (vconcat [?\C-u 1 ?\M-x] (string-to-vector mode)))) 10 | (execute-kbd-macro v)))) 11 | 12 | ;; Loads CONTENTS with Emacs load command. 13 | ;; 14 | ;; Usage: 15 | ;; When I load the following: 16 | ;; """ 17 | ;; CONTENTS 18 | ;; """ 19 | (When "^I load the following:$" 20 | (lambda (contents) 21 | (espuds-fake-eval contents))) 22 | 23 | ;; Creates a new temp file called FILE and opens it. 24 | ;; 25 | ;; Usage: 26 | ;; When I open temp file "SOME FILE" 27 | (When "^I open temp file \"\\(.+\\)\"$" 28 | (lambda (file) 29 | (find-file (make-temp-file file)))) 30 | 31 | ;; Asserts that MESSAGE has been printed. 32 | ;; 33 | ;; Usage: 34 | ;; Then I should see message "MESSAGE" 35 | (Then "^I should see message \"\\(.+\\)\"$" 36 | (lambda (message) 37 | (save-excursion 38 | (set-buffer "*Messages*") 39 | (let ((search (search message (espuds-buffer-contents)))) 40 | (assert 41 | search nil "Expected '%s' to be included in the list of printed messages, but was not." message))))) 42 | 43 | 44 | (provide 'espuds-misc) 45 | 46 | ;;; espuds-misc.el ends here 47 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Espuds - Ecukes step definitions 2 | 3 | First of all. If you don't know what 4 | [Ecukes](http://github.com/rejeep/ecukes) it, go read up about it. If 5 | you have, you should know that in order to test with Ecukes, you need 6 | to translate your steps so that Emacs understands them. You do that 7 | with step definitions. 8 | 9 | Espuds is a collection of the most commonly used step definitions. 10 | 11 | 12 | ## Usage 13 | To use Espuds, you have load it in your **features/support.el** file. 14 | (add-to-list 'load-path "/path/to/espuds) 15 | (require 'espuds) 16 | 17 | Thats it! 18 | 19 | 20 | ## Step Definitions 21 | See source file for description of each step definition. 22 | 23 | 24 | ## Gotchas 25 | 26 | ### Action Chain 27 | Some actions require more than one keyboard input. For example 28 | functions that reads input via the minibuffer (not via interactive). 29 | 30 | To handle such cases, you wrap the actions in a block. For example: 31 | Scenario: Activate linum mode 32 | Given I start an action chain 33 | And I press "M-x" 34 | And I type "linum-mode" 35 | And I execute the action chain 36 | Then linum-mode should be active 37 | 38 | ## Contributing 39 | We all test different kind of applications. It is therefore important 40 | that you contribute the step definitions you find useful. Send me an 41 | email, a pm, a pull request or create an issue with your improvement. 42 | -------------------------------------------------------------------------------- /espuds.el: -------------------------------------------------------------------------------- 1 | ;;; espuds.el --- Ecukes step definitions 2 | 3 | ;; Copyright (C) 2010 Johan Andersson 4 | 5 | ;; Author: Johan Andersson 6 | ;; Maintainer: Johan Andersson 7 | ;; Version: 0.1.0 8 | ;; Keywords: test 9 | ;; URL: http://github.com/rejeep/espuds 10 | 11 | ;; This file is NOT part of GNU Emacs. 12 | 13 | ;;; License: 14 | 15 | ;; This program is free software; you can redistribute it and/or modify 16 | ;; it under the terms of the GNU General Public License as published by 17 | ;; the Free Software Foundation; either version 3, or (at your option) 18 | ;; any later version. 19 | 20 | ;; This program is distributed in the hope that it will be useful, 21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | ;; GNU General Public License for more details. 24 | 25 | ;; You should have received a copy of the GNU General Public License 26 | ;; along with GNU Emacs; see the file COPYING. If not, write to the 27 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 28 | ;; Boston, MA 02110-1301, USA. 29 | 30 | ;;; Commentary: 31 | 32 | ;;; Code: 33 | 34 | (eval-when-compile 35 | (require 'edmacro) 36 | (require 'cl) 37 | (require 'espuds-helpers) 38 | (require 'espuds-buffer) 39 | (require 'espuds-text) 40 | (require 'espuds-input) 41 | (require 'espuds-movement) 42 | (require 'espuds-region) 43 | (require 'espuds-misc)) 44 | 45 | (provide 'espuds) 46 | 47 | ;;; espuds.el ends here 48 | -------------------------------------------------------------------------------- /espuds-buffer.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-buffer.el --- Buffer related definitions 2 | 3 | 4 | ;; Switches to BUFFER. 5 | ;; 6 | ;; Usage: 7 | ;; When I switch to buffer "Foo" 8 | ;; Given I am in buffer "*scratch*" 9 | (Given "^\\(?:I am in buffer\\|I switch to buffer\\) \"\\(.+\\)\"$" 10 | (lambda (buffer) 11 | (let ((v (vconcat [?\C-x ?b] (string-to-vector buffer)))) 12 | (execute-kbd-macro v)))) 13 | 14 | ;; Asserts that the current buffer is BUFFER. 15 | ;; 16 | ;; Usage: 17 | ;; Then I should be in buffer "*scratch*" 18 | (Then "^I should be in buffer \"\\(.+\\)\"$" 19 | (lambda (buffer) 20 | (let ((message "Expected to be in buffer '%s', but was in '%s'")) 21 | (assert (equal buffer (buffer-name)) nil message buffer (buffer-name))))) 22 | 23 | 24 | ;; Asserts that the current buffer is connected to FILE. 25 | ;; 26 | ;; Usage: 27 | ;; Then I should be in file "/path/to/some/file" 28 | (Then "^I should be in file \"\\(.+\\)\"$" 29 | (lambda (file) 30 | (let ((file-name (buffer-file-name))) 31 | (assert file-name nil "Expected file to be '%s', but not visiting any file." file) 32 | (let ((match (string-match-p (concat file "$") file-name))) 33 | (assert match nil "Expected file to be '%s', but was '%s'." file file-name))))) 34 | 35 | 36 | ;; Clears all text in the current buffer. 37 | ;; 38 | ;; Usage: 39 | ;; Given the buffer is empty 40 | ;; When I clear the buffer 41 | (Given "^the buffer is empty$\\|^I clear the buffer$" 42 | (lambda () 43 | (erase-buffer))) 44 | 45 | 46 | (provide 'espuds-buffer) 47 | 48 | ;;; espuds-buffer.el ends here 49 | -------------------------------------------------------------------------------- /espuds-region.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-region.el --- region related definitions 2 | 3 | 4 | ;; Deactivates mark. 5 | ;; 6 | ;; Usage: 7 | ;; Given there is no region selected 8 | (Given "^there is no region selected$" 9 | (lambda () 10 | (deactivate-mark))) 11 | 12 | ;; Activates transient mark mode. 13 | ;; 14 | ;; Usage: 15 | ;; Given transient mark mode is active 16 | ;; Given transient mark mode is inactive 17 | (Given "^transient mark mode is \\(active\\|inactive\\)$" 18 | (lambda (status) 19 | (transient-mark-mode 20 | (if (string= status "active") 1 -1)))) 21 | 22 | ;; Sets the mark at point. 23 | ;; 24 | ;; Usage: 25 | ;; When I set the mark 26 | (When "^I set the mark$" 27 | (lambda () 28 | (set-mark (point)))) 29 | 30 | ;; Pop and move point to the top position on the mark-ring 31 | ;; 32 | ;; Usage: 33 | ;; When I pop the mark 34 | (When "^I pop the mark$" 35 | (lambda () 36 | (set-mark-command 4))) 37 | 38 | ;; Asserts that the selected region is same as EXPECTED. 39 | ;; 40 | ;; Usage: 41 | ;; Then the region should be "REGION" 42 | ;; 43 | ;; Then the region should be: 44 | ;; """ 45 | ;; REGION 46 | ;; """ 47 | (Then "^the region should be\\(?: \"\\(.*\\)\"\\|:\\)$" 48 | (lambda (expected) 49 | (let ((actual (espuds-region)) 50 | (message "Expected the region to be '%s', but was '%s'.")) 51 | (assert (equal expected actual) nil message expected actual)))) 52 | 53 | ;; Asserts that the region is not active. 54 | ;; 55 | ;; Usage: 56 | ;; Then the region should not be active 57 | (Then "^the region should not be active$" 58 | (lambda () 59 | (let ((message "Expected the region not to be active, but it was.")) 60 | (assert (not (region-active-p)) nil message)))) 61 | 62 | (provide 'espuds-region) 63 | 64 | ;;; espuds-region.el ends here 65 | -------------------------------------------------------------------------------- /espuds-input.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-input.el --- Input related definitions 2 | 3 | 4 | (defvar espuds-action-chain '() 5 | "List of actions to execute.") 6 | 7 | (defvar espuds-chain-active nil 8 | "Is t if chaining is active, nil otherwise.") 9 | 10 | 11 | ;; Starts an action chain. 12 | ;; 13 | ;; Usage: 14 | ;; When I start an action chain 15 | (When "^I start an action chain$" 16 | (lambda () 17 | (setq espuds-action-chain '()) 18 | (setq espuds-chain-active t))) 19 | 20 | ;; Executes the action chain. 21 | ;; 22 | ;; Usage: 23 | ;; When I execute the action chain 24 | (When "^I execute the action chain$" 25 | (lambda () 26 | (execute-kbd-macro espuds-action-chain) 27 | (setq espuds-chain-active nil))) 28 | 29 | ;; If action chaining is active. Add KEYBINDING to the action 30 | ;; chain. Otherwise execute the function that KEYBINDING is bound to. 31 | ;; 32 | ;; Usage: 33 | ;; When I press "C-h e" 34 | (When "^I press \"\\(.+\\)\"$" 35 | (lambda (keybinding) 36 | (let ((macro (edmacro-parse-keys keybinding))) 37 | (if espuds-chain-active 38 | (setq espuds-action-chain (vconcat espuds-action-chain macro)) 39 | (if (and (equal keybinding "C-g") 40 | (eq (key-binding (kbd "C-g")) 'keyboard-quit)) 41 | (espuds-quit) 42 | (execute-kbd-macro macro)))))) 43 | 44 | ;; Quit without signal. 45 | ;; 46 | ;; Usage: 47 | ;; When I quit 48 | (When "^I quit$" 'espuds-quit) 49 | 50 | ;; If action chaining is active. Add TYPING to the action 51 | ;; chain. Otherwise simulate the TYPING. 52 | ;; 53 | ;; Usage: 54 | ;; When I type "TYPING" 55 | (Given "^I type \"\\(.+\\)\"$" 56 | (lambda (typing) 57 | (if espuds-chain-active 58 | (setq espuds-action-chain (vconcat espuds-action-chain (string-to-vector typing))) 59 | (execute-kbd-macro (string-to-vector typing))))) 60 | 61 | 62 | (provide 'espuds-input) 63 | 64 | ;;; espuds-input.el ends here 65 | -------------------------------------------------------------------------------- /espuds-text.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-text.el --- Text related definitions 2 | 3 | ;; Inserts CONTENTS into the current buffer. 4 | ;; 5 | ;; Usage: 6 | ;; When I insert "CONTENTS" 7 | ;; 8 | ;; When I insert: 9 | ;; """ 10 | ;; CONTENTS 11 | ;; """ 12 | (When "^I insert\\(?: \"\\(.+\\)\"\\|:\\)$" 13 | (lambda (contents) 14 | (insert contents))) 15 | 16 | 17 | ;; Asserts that the current buffer includes some text. 18 | ;; 19 | ;; Usage: 20 | ;; Then I should see "CONTENTS" 21 | ;; 22 | ;; Then I should see: 23 | ;; """ 24 | ;; CONTENTS 25 | ;; """ 26 | (Then "^I should see\\(?: \"\\(.+\\)\"\\|:\\)$" 27 | (lambda (expected) 28 | (let ((actual (espuds-buffer-contents)) 29 | (message "Expected '%s' to be part of '%s', but was not.")) 30 | (assert (search expected actual) nil message expected actual)))) 31 | 32 | ;; Asserts that the current buffer does not include some text. 33 | ;; 34 | ;; Usage: 35 | ;; Then I should not see "CONTENTS" 36 | ;; 37 | ;; Then I should not see: 38 | ;; """ 39 | ;; CONTENTS 40 | ;; """ 41 | (Then "^I should not see\\(?: \"\\(.+\\)\"\\|:\\)$" 42 | (lambda (expected) 43 | (let ((actual (espuds-buffer-contents)) 44 | (message "Expected '%s' to not be part of '%s', but was.")) 45 | (assert (not (search expected actual)) nil message expected actual)))) 46 | 47 | 48 | ;; Asserts that the current buffer matches some text. 49 | ;; 50 | ;; Usage: 51 | ;; Then I should see pattern "CONTENTS" 52 | ;; 53 | ;; Then I should see pattern: 54 | ;; """ 55 | ;; CONTENTS 56 | ;; """ 57 | (Then "^I should see pattern\\(?: \"\\(.+\\)\"\\|:\\)$" 58 | (lambda (expected) 59 | (let ((actual (espuds-buffer-contents)) 60 | (message "Expected to see pattern '%s' in '%s', but did not.")) 61 | (assert 62 | (string-match-p expected actual) nil message expected actual)))) 63 | 64 | ;; Asserts that the current buffer does not match some text. 65 | ;; 66 | ;; Usage: 67 | ;; Then I should not see pattern "CONTENTS" 68 | ;; 69 | ;; Then I should not see pattern: 70 | ;; """ 71 | ;; CONTENTS 72 | ;; """ 73 | (Then "^I should not see pattern\\(?: \"\\(.+\\)\"\\|:\\)$" 74 | (lambda (expected) 75 | (let ((actual (espuds-buffer-contents)) 76 | (message "Expected to not see pattern '%s' in '%s', but did.")) 77 | (assert 78 | (not (string-match-p expected actual)) nil message expected actual)))) 79 | 80 | ;; Selects TEXT if found. Otherwise signal an error. 81 | ;; 82 | ;; Usage: 83 | ;; When I select "SOME TEXT" 84 | ;; 85 | (When "^I select \"\\(.+\\)\"$" 86 | (lambda (text) 87 | (goto-char (point-min)) 88 | (let ((search (re-search-forward text nil t))) 89 | (assert search nil "The text '%s' was not found in the current buffer." text)) 90 | (set-mark (point)) 91 | (re-search-backward text))) 92 | 93 | ;; Asserts that there nothing to see in the current buffer. 94 | ;; 95 | ;; Usage: 96 | ;; Then I should not see anything 97 | ;; Then the buffer should be empty 98 | (Then "^I should not see anything$\\|^the buffer should be empty$" 99 | (lambda () 100 | (let ((message "Expected buffer to be empty, but had content: '%s'")) 101 | (assert (equal (buffer-size) 0) nil message (espuds-buffer-contents))))) 102 | 103 | 104 | (provide 'espuds-text) 105 | 106 | ;;; espuds-text.el ends here 107 | -------------------------------------------------------------------------------- /espuds-movement.el: -------------------------------------------------------------------------------- 1 | ;;; espuds-movement.el --- Movement related definitions 2 | 3 | 4 | ;; Goes to LINE if it exist. 5 | ;; 6 | ;; Usage: 7 | ;; When I go to line "12" 8 | (When "^I go to line \"\\([0-9]+\\)\"$" 9 | (lambda (line) 10 | (let ((num-lines (count-lines (point-min) (point-max))) 11 | (line-num (string-to-number line)) 12 | (message "Requested line '%s', but buffer only has '%d' line(s).")) 13 | (assert (<= line-num num-lines) nil message line num-lines) 14 | (goto-line line-num)))) 15 | 16 | ;; Goes to POINT if it exist. 17 | ;; 18 | ;; Usage: 19 | ;; When I go to point "12" 20 | (When "^I go to point \"\\([0-9]+\\)\"$" 21 | (lambda (point) 22 | (let ((size (buffer-size)) 23 | (point-num (string-to-number point)) 24 | (message "Requested point '%s', but buffer only has '%d' point(s).")) 25 | (assert (<= (1- point-num) size) nil message point-num size) 26 | (goto-char point-num)))) 27 | 28 | ;; Go to WORD if it exist. 29 | ;; 30 | ;; Usage: 31 | ;; When I go to word "SOME WORD" 32 | (When "^I go to word \"\\(.+\\)\"$" 33 | (lambda (word) 34 | (goto-char (point-min)) 35 | (let ((search (re-search-forward (format "\\b%s\\b" word) nil t)) 36 | (message "Can not go to word '%s' since it does not exist in the current buffer: %s")) 37 | (assert search nil message word (espuds-buffer-contents))) 38 | (backward-char (length word)))) 39 | 40 | ;; Checks that the cursor is at a specific position. 41 | ;; 42 | ;; Usage: 43 | ;; Then the cursor should be at point "12" 44 | (Then "^the cursor should be at point \"\\(.+\\)\"$" 45 | (lambda (point) 46 | (let ((message "Expected cursor to be at point '%s', but was at '%s'")) 47 | (assert (= (string-to-number point) (point)) nil message point (point))))) 48 | 49 | ;; Checks that the cursor is before some text. 50 | ;; 51 | ;; Usage: 52 | ;; Then the cursor should be before "Foo" 53 | (Then "^the cursor should be before \"\\(.+\\)\"$" 54 | (lambda (expected) 55 | (let ((actual 56 | (progn 57 | (buffer-substring-no-properties (point) (min (point-max) (+ (point) 5))))) 58 | (message "Expected '%s' to be before point but was '%s'.")) 59 | (assert (looking-at (regexp-quote expected)) nil message expected actual)))) 60 | 61 | ;; Checks that the cursor is after some text. 62 | ;; 63 | ;; Usage: 64 | ;; Then the cursor should be after "Foo" 65 | (Then "^the cursor should be after \"\\(.+\\)\"$" 66 | (lambda (expected) 67 | (let ((actual 68 | (progn 69 | (buffer-substring-no-properties (point) (max (point-min) (- (point) 5))))) 70 | (message "Expected '%s' to be after point but was '%s'.")) 71 | (assert (looking-back (regexp-quote expected)) nil message expected actual)))) 72 | 73 | ;; Checks that the cursor is between some text. 74 | ;; 75 | ;; Usage: 76 | ;; Then the cursor should be between "Foo" and "Bar" 77 | (Then "^the cursor should be between \"\\(.+\\)\" and \"\\(.+\\)\"$" 78 | (lambda (left right) 79 | (let ((search 80 | (and 81 | (looking-back (regexp-quote left)) 82 | (looking-at (regexp-quote right)))) 83 | (message "Expected '%s' to be left of point and '%s' to be right of point, but was: '%s[CURSOR]%s'") 84 | (before 85 | (buffer-substring-no-properties 86 | (max (point-min) (- (point) 5)) 87 | (point))) 88 | (after 89 | (buffer-substring-no-properties 90 | (point) 91 | (min (point-max) (+ (point) 5))))) 92 | (assert search nil message left right before after)))) 93 | 94 | ;; Places the cursor between text. 95 | ;; 96 | ;; Usage: 97 | ;; When I place the cursor between "Foo" and "Bar" 98 | (When "^I place the cursor between \"\\(.+\\)\" and \"\\(.+\\)\"$" 99 | (lambda (left right) 100 | (goto-char (point-min)) 101 | (let ((search (search-forward (concat left right) nil t)) 102 | (message "Can not place cursor between '%s' and '%s', because there is no such point: '%s'")) 103 | (assert search nil message left right (espuds-buffer-contents))) 104 | (backward-char (length right)))) 105 | 106 | ;; Places the cursor after first instance of text. 107 | ;; 108 | ;; Usage: 109 | ;; When I place the cursor after "Foo" 110 | (When "^I place the cursor after \"\\(.+\\)\"$" 111 | (lambda (arg) 112 | (goto-char (point-min)) 113 | (let ((search (search-forward arg nil t)) 114 | (message "Can not place cursor after '%s', because there is no such point: '%s'")) 115 | (assert search nil message arg (espuds-buffer-contents))))) 116 | 117 | ;; Places the cursor at the beginning of buffer. 118 | ;; 119 | ;; Usage: 120 | ;; When I go to beginning of buffer 121 | (When "^I go to beginning of buffer$" 'beginning-of-buffer) 122 | 123 | ;; Places the cursor at the end of buffer. 124 | ;; 125 | ;; Usage: 126 | ;; When I go to end of buffer 127 | (When "^I go to end of buffer$" 'end-of-buffer) 128 | 129 | 130 | (provide 'espuds-movement) 131 | 132 | ;;; espuds-movement.el ends here 133 | --------------------------------------------------------------------------------