Browse files

Be smarter when fetching project root.

  • Loading branch information...
1 parent 66fc96c commit a6fed0c1d5068971a67708f33940ea62357be6bf @rejeep rejeep committed Nov 25, 2012
Showing with 51 additions and 34 deletions.
  1. +7 −2 ecukes-project.el
  2. +18 −14 test/ecukes-new-test.el
  3. +12 −10 test/ecukes-project-test.el
  4. +9 −8 test/ecukes-setup-test.el
  5. +5 −0 test/test-helper.el
View
9 ecukes-project.el
@@ -1,8 +1,13 @@
;;; ecukes-project.el --- Project helpers
-(defun ecukes-project-path ()
+(defun ecukes-project-path (&optional dir)
"Path to project."
- (directory-file-name (expand-file-name default-directory)))
+ (or dir (setq dir default-directory))
+ (if (file-directory-p (expand-file-name "features" dir))
+ (directory-file-name dir)
+ (let ((new-dir (expand-file-name (file-name-as-directory "..") dir)))
+ (unless (equal dir "/")
+ (ecukes-project-path new-dir)))))
(defun ecukes-project-name ()
"Name of the project."
View
32 test/ecukes-new-test.el
@@ -34,29 +34,33 @@
(ert-deftest new-should-create-root ()
"Should create features directory."
(with-mock
- (mock (make-directory) :times 1)
- (mock (ecukes-new-message) :times 1)
- (ecukes-new-create-root)))
+ (with-project
+ (mock (make-directory "/path/to/project/features") :times 1)
+ (mock (ecukes-new-message) :times 1)
+ (ecukes-new-create-root))))
(ert-deftest new-should-create-step-definitions ()
"Should create step definitions directory and step definition."
(with-mock
- (mock (make-directory) :times 1)
- (mock (ecukes-template-write) :times 1)
- (mock (ecukes-new-message) :times 2)
- (ecukes-new-create-step-definitions)))
+ (with-project
+ (mock (make-directory "/path/to/project/features/step-definitions") :times 1)
+ (mock (ecukes-template-write) :times 1)
+ (mock (ecukes-new-message) :times 2)
+ (ecukes-new-create-step-definitions))))
(ert-deftest new-should-create-support ()
"Should create support directory with env file."
(with-mock
- (mock (make-directory) :times 1)
- (mock (ecukes-template-write) :times 1)
- (mock (ecukes-new-message) :times 2)
- (ecukes-new-create-support)))
+ (with-project
+ (mock (make-directory "/path/to/project/features/support") :times 1)
+ (mock (ecukes-template-write "/path/to/project/features/support/env.el") :times 1)
+ (mock (ecukes-new-message) :times 2)
+ (ecukes-new-create-support))))
(ert-deftest new-should-create-feature ()
"Should create feature file."
(with-mock
- (mock (ecukes-template-write) :times 1)
- (mock (ecukes-new-message) :times 1)
- (ecukes-new-create-feature)))
+ (with-project
+ (mock (ecukes-template-write "/path/to/project/features/project.feature") :times 1)
+ (mock (ecukes-new-message) :times 1)
+ (ecukes-new-create-feature))))
View
22 test/ecukes-project-test.el
@@ -2,25 +2,27 @@
(ert-deftest project-path ()
"Should return correct project path."
- (let ((default-directory "/path/to/project/"))
- (should (equal "/path/to/project" (ecukes-project-path)))))
+ (with-mock
+ (stub file-directory-p => t)
+ (let ((default-directory "/path/to/project/"))
+ (should (equal "/path/to/project" (ecukes-project-path))))))
(ert-deftest project-name ()
"Should return correct project name."
- (let ((default-directory "/path/to/project/"))
- (should (equal "project" (ecukes-project-name)))))
+ (with-project
+ (should (equal "project" (ecukes-project-name)))))
(ert-deftest project-features-path ()
"Should return correct project features path."
- (let ((default-directory "/path/to/project"))
- (should (equal "/path/to/project/features" (ecukes-project-features-path)))))
+ (with-project
+ (should (equal "/path/to/project/features" (ecukes-project-features-path)))))
(ert-deftest project-support-path ()
"Should return correct project support path."
- (let ((default-directory "/path/to/project"))
- (should (equal "/path/to/project/features/support" (ecukes-project-support-path)))))
+ (with-project
+ (should (equal "/path/to/project/features/support" (ecukes-project-support-path)))))
(ert-deftest project-step-definition-path ()
"Should return correct project step definition path."
- (let ((default-directory "/path/to/project"))
- (should (equal "/path/to/project/features/step-definitions" (ecukes-project-step-definitions-path)))))
+ (with-project
+ (should (equal "/path/to/project/features/step-definitions" (ecukes-project-step-definitions-path)))))
View
17 test/ecukes-setup-test.el
@@ -116,14 +116,15 @@
(ert-deftest setup-load-support ()
"Should load support first and only once, then the rest."
(with-mock
- (stub expand-file-name => "/path/to/project/features/support/env.el")
- (stub
- directory-files =>
- '("/path/to/project/features/support/env.el"
- "/path/to/project/features/support/foo.el"
- "/path/to/project/features/support/bar.el"))
- (mock (load) :times 3)
- (ecukes-setup-load-support)))
+ (with-project
+ (stub expand-file-name => "/path/to/project/features/support/env.el")
+ (stub
+ directory-files =>
+ '("/path/to/project/features/support/env.el"
+ "/path/to/project/features/support/foo.el"
+ "/path/to/project/features/support/bar.el"))
+ (mock (load) :times 3)
+ (ecukes-setup-load-support))))
(ert-deftest setup-load-step-definitions ()
"Should load all step definitions."
View
5 test/test-helper.el
@@ -80,6 +80,11 @@
(ecukes-stats-scenarios-failed 0))
,@body))
+(defmacro with-project (&rest body)
+ `(with-mock
+ (stub ecukes-project-path => "/path/to/project")
+ ,@body))
+
(defun fixture-file-path (category name)
(let ((category-path (expand-file-name category ecukes-fixtures-path)))
(expand-file-name (format "%s.feature" name) category-path)))

0 comments on commit a6fed0c

Please sign in to comment.