Skip to content

Commit

Permalink
Move print stuff to ecukes-print.el and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rejeep committed Feb 21, 2013
1 parent a4479f8 commit d1923aa
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 25 deletions.
28 changes: 8 additions & 20 deletions ecukes-cli.el
Expand Up @@ -6,33 +6,21 @@

(add-to-list 'load-path ecukes-path)

(require 'ecukes)
(require 'ecukes-helpers)
(require 'ecukes-setup)
(require 'ecukes-project)
(require 'ecukes-print)

(defun ecukes-print-steps (&optional with-doc with-file)
"Print all available steps defined for this project.
Include docstring when WITH-DOC is non-nil."
(ecukes-assert-in-project)
(ecukes-setup)
(-map
(lambda (step-def)
(when with-file
(let ((file (ecukes-step-file-name step-def t)))
(princ file)
(princ ": ")))
(princ (ansi-green (ecukes-step-def-regex step-def)))
(princ "\n")
(when (and with-doc (ecukes-step-def-doc step-def))
(princ (ecukes-step-def-doc step-def))
(princ "\n")))
ecukes-steps-definitions))
(ecukes-setup)

This comment has been minimized.

Copy link
@tkf

tkf Feb 21, 2013

Contributor

Why not move (ecukes-setup) into ecukes-cli-print-steps? It's just an idea, but if you don't call function at top level, you can use this file for entry point for other CLI functions. For example, you can remove ecukes-path from ecukes-new.el, require it from here and replace $ECUKES_NEW to $ECUKES_CLI in the bash script. Same goes for ecukes-term.el.

This comment has been minimized.

Copy link
@rejeep

rejeep Feb 22, 2013

Author Contributor

Good idea. See 7d562ee


(defun ecukes-cli-print-steps ()
(let ((has (lambda (flag)
(when (member flag command-line-args-left)
(setq command-line-args-left
(delete flag command-line-args-left))
t))))
(ecukes-print-steps (funcall has "--with-doc")
(funcall has "--with-file"))))
(ecukes-print-steps
(funcall has "--with-doc")
(funcall has "--with-file"))))

;;; ecukes-cli.el ends here
19 changes: 19 additions & 0 deletions ecukes-print.el
Expand Up @@ -3,6 +3,7 @@
(require 'ansi)

(require 'ecukes-stats)
(require 'ecukes-def)
(require 'ecukes-steps)
(require 'ecukes-template)

Expand Down Expand Up @@ -178,6 +179,24 @@
'ansi-cyan))))
(funcall color string)))

(defun ecukes-print-steps (&optional with-doc with-file)
"Print all available steps defined for this project.
Include docstring when WITH-DOC is non-nil."
(-map
(lambda (step-def)
(let ((row))
(when with-file
(let ((file (ecukes-step-file-name step-def t)))
(setq row (s-concat row file ": "))))
(let ((regex (ecukes-step-def-regex step-def)))
(setq row (s-concat row (ansi-green regex))))
(when with-doc
(let ((doc (ecukes-step-def-doc step-def)))
(when doc
(setq row (s-concat row "\n" doc)))))
(ecukes-print-message row)))
ecukes-steps-definitions))

(defun ecukes-print-stats-summary ()
"Print stats summary."
(ecukes-print-message (ecukes-stats-summary)))
Expand Down
7 changes: 2 additions & 5 deletions ecukes.el
Expand Up @@ -11,13 +11,10 @@
(require 'ecukes-setup)
(require 'ansi-color)

(defun ecukes-assert-in-project ()
(unless (ecukes-project-path)
(error "You are not visiting an Ecukes project.")))

(defun ecukes (&optional ask-for-tags)
(interactive "P")
(ecukes-assert-in-project)
(unless (ecukes-project-path)
(error "You are not visiting an Ecukes project."))
(ecukes-setup)
(if ask-for-tags
(ecukes-setup-tags (read-string "Run tags: ")))
Expand Down
56 changes: 56 additions & 0 deletions test/ecukes-print-test.el
Expand Up @@ -371,6 +371,62 @@
(ecukes-print-py-string step 'skipped)
(should (equal messages expected))))))

(ert-deftest print-steps-no-docs-or-file ()
"Should print list of steps with no docs or file."
(with-steps
(Given "^a known state$" 'ignore)
(Given "^an unknown state$" 'ignore)
(with-messages
(lambda (messages)
(let ((expected
(list
(ansi-green "^an unknown state$")
(ansi-green "^a known state$"))))
(ecukes-print-steps)
(should (equal messages expected)))))))

(ert-deftest print-steps-with-docs ()
"Should print list of steps with docs but no file."
(with-steps
(Given "^a known state$" "Will be in a known state" 'ignore)
(Given "^an unknown state$" "Will be in an unknown state" 'ignore)
(with-messages
(lambda (messages)
(let ((expected
(list
(concat (ansi-green "^an unknown state$") "\nWill be in an unknown state")
(concat (ansi-green "^a known state$") "\nWill be in a known state"))))
(ecukes-print-steps t)
(should (equal messages expected)))))))

(ert-deftest print-steps-with-file ()
"Should print list of steps with file but no docs."
(with-steps
(Given "^a known state$" "Will be in a known state" 'ignore)
(Given "^an unknown state$" "Will be in an unknown state" 'ignore)
(with-messages
(lambda (messages)
(let ((expected
(list
(concat "test/ecukes-test: " (ansi-green "^an unknown state$"))
(concat "test/ecukes-test: " (ansi-green "^a known state$")))))
(ecukes-print-steps nil t)
(should (equal messages expected)))))))

(ert-deftest print-steps-with-file-and-docs ()
"Should print list of steps with file and docs."
(with-steps
(Given "^a known state$" "Will be in a known state" 'ignore)
(Given "^an unknown state$" "Will be in an unknown state" 'ignore)
(with-messages
(lambda (messages)
(let ((expected
(list
(concat "test/ecukes-test: " (ansi-green "^an unknown state$") "\nWill be in an unknown state")
(concat "test/ecukes-test: " (ansi-green "^a known state$") "\nWill be in a known state"))))
(ecukes-print-steps t t)
(should (equal messages expected)))))))

(ert-deftest print-status-success ()
"Should print in green when success."
(with-mock
Expand Down

0 comments on commit d1923aa

Please sign in to comment.