Permalink
Browse files

Move print stuff to ecukes-print.el and add tests.

  • Loading branch information...
1 parent a4479f8 commit d1923aa3074b0418f6723d6b91c51eec12d0e9bd @rejeep rejeep committed Feb 21, 2013
Showing with 85 additions and 25 deletions.
  1. +8 −20 ecukes-cli.el
  2. +19 −0 ecukes-print.el
  3. +2 −5 ecukes.el
  4. +56 −0 test/ecukes-print-test.el
View
@@ -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)
@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.

@rejeep

rejeep Feb 22, 2013

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
View
@@ -3,6 +3,7 @@
(require 'ansi)
(require 'ecukes-stats)
+(require 'ecukes-def)
(require 'ecukes-steps)
(require 'ecukes-template)
@@ -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)))
View
@@ -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: ")))
View
@@ -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

0 comments on commit d1923aa

Please sign in to comment.