Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 891ad53ac2fdba88a9ec4b3ba80ff6633088d9e1 0 parents
Nils Wloka authored
6 .gitignore
@@ -0,0 +1,6 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-failures
+.lein-deps-sum
26 README.md
@@ -0,0 +1,26 @@
+# lein-cucumber
+
+This is a very simple leiningen plugin for use with [cucumber-jvm](https://github.com/cucumber/cucumber-jvm).
+
+## Usage
+
+1. Add `[lein-cucumber "0.1.0"]` to `:dev-dependencies` in your project.clj
+2. Run `lein deps` to fetch all dependencies.
+3. Run all Cucumber features with `lein cucumber`
+
+## Please note
+
+In the current version, you cannot specify any configuration options. The following settings are hard-coded into the plugin:
+
+* A progress report will be printed to the console.
+* The complete report (formatted with `PrettyFormatter`) will be written to `test-reports/cucumber.out`. Consider adding `:extra-files-to-clean ["test-reports"]` to your project.clj.
+* Leiningen will exit with the exit status of the cucumber-jvm [runtime](https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/Runtime.java).
+* Put your `.feature` files into `test/features/`
+* Put your step definitions into `test/features/step_definitions/`
+
+See https://github.com/cucumber/cucumber-jvm/tree/master/clojure/src/test/resources/cucumber/runtime/clojure for an example specification.
+
+## Unlicense
+
+Written by Nils Wloka, 2012. For licensing information, see UNLICENSE.
+Please have a look at http://unlicense.org if you plan to contribute.
24 UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
7 project.clj
@@ -0,0 +1,7 @@
+(defproject lein-cucumber "0.1.0"
+ :description "Run cucumber-jvm specifications with leiningen"
+ :dependencies [[info.cukes/cucumber-clojure "1.0.0.RC13"]]
+ :eval-in-leiningen true
+ :license {:name "Unlicense"
+ :url "http://unlicense.org/"
+ :distribution :repo})
18 src/leiningen/cucumber.clj
@@ -0,0 +1,18 @@
+(ns leiningen.cucumber
+ (:use [leiningen.compile :only [eval-in-project]])
+ (:require [leiningen.core :as core]))
+
+(defn cucumber
+ "Runs Cucumber features in test/features with glue in test/features/step_definitions"
+ [project]
+ (let [runtime (gensym "runtime")]
+ (eval-in-project
+ project
+ `(do
+ (let [~runtime (leiningen.cucumber.util/run-cucumber!)]
+ (println)
+ ~(when-not core/*interactive?*
+ `(System/exit (.exitStatus ~runtime)))))
+ nil
+ nil
+ '(require 'leiningen.cucumber.util))))
46 src/leiningen/cucumber/util.clj
@@ -0,0 +1,46 @@
+(ns leiningen.cucumber.util
+ (:use [clojure.java.io])
+ (:import [gherkin.formatter PrettyFormatter])
+ (:import [cucumber.formatter FormatterFactory MultiFormatter])
+ (:import [cucumber.io FileResourceLoader])
+ (:import [cucumber.cli DefaultRuntimeFactory])
+ (:import [cucumber.runtime.snippets SummaryPrinter])
+ (:import [java.io File])
+ (:import [java.util ArrayList]))
+
+(defn- report-writer []
+ (let [report-directory (file "test-reports")
+ report-file (file report-directory "cucumber.out")]
+ (make-parents report-file)
+ (writer report-file)))
+
+(defn- create-multi-formatter []
+ (let [classloader (.getContextClassLoader (Thread/currentThread))
+ formatter-factory (FormatterFactory. classloader)
+ multi-formatter (MultiFormatter. classloader)
+ out (report-writer)
+ formatter (PrettyFormatter. out true true)]
+ (doto multi-formatter
+ (.add formatter)
+ (.add (.createFormatter formatter-factory "progress" System/out)))
+ multi-formatter))
+
+(defn- create-runtime []
+ (let [runtime-factory (DefaultRuntimeFactory.)
+ classloader (.getContextClassLoader (Thread/currentThread))
+ glue-paths (ArrayList. ["test/features/step_definitions"])
+ file-resource-loader (FileResourceLoader.)]
+ (.createRuntime runtime-factory file-resource-loader glue-paths classloader false)))
+
+(defn run-cucumber! []
+ (let [multi-formatter (create-multi-formatter)
+ runtime (create-runtime)
+ feature-paths (ArrayList. ["test/features"])
+ formatter (.formatterProxy multi-formatter)
+ reporter (.reporterProxy multi-formatter)
+ summary-printer (SummaryPrinter. System/out)]
+ (.run runtime feature-paths (ArrayList.) formatter reporter)
+ (.done formatter)
+ (.print summary-printer runtime)
+ (.close formatter)
+ runtime))
Please sign in to comment.
Something went wrong with that request. Please try again.