Skip to content

Commit fd2645a

Browse files
committed
Fixed issue skipoleschris#15. Templemore repository is now added as a resolver to any project using the plugin.
Fixed issue skipoleschris#14. It is now possible to run cucumber in the IntegrationTest config.
1 parent dc389d2 commit fd2645a

File tree

17 files changed

+135
-12
lines changed

17 files changed

+135
-12
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ project/target
55
.idea/workspace.xml
66
.ensime_port
77
xsbt-cucumber-plugin.sublime-workspace
8+
deploy-repo
9+

Diff for: README.markdown

+37-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ xsbt-cucumber-plugin
33

44
An [sbt 0.12.x](https://github.com/harrah/xsbt/wiki) plugin for running [Cucumber](http://cukes.info) features.
55

6-
### IMPORTANT NOTES ABOUT THIS RELEASE (0.7.0) ###
7-
It adds the ability to run cucumber as a standalone SBT task but also as a test runner within the standard 'test' task. To facilitate this, there has been one significant change that you should be aware of: the default location for feature files has changed from the src/test/features directory to the classpath. This is required as running as a test framework only has access to the test classpath. Features should therefore now live under src/test/resources. It is possible to change this back to another location by overriding the cucumberFeaturesLocation setting, but if you change this to anything other than the classpath then the 'test' task will not be able to find features.
6+
### IMPORTANT NOTES ABOUT THIS RELEASE (0.7.x) ###
7+
It adds the ability to run cucumber as a standalone SBT task but also as a test runner within the standard 'test' task (either within the Test or within the IntegrationTest configs). To facilitate this, there has been one significant change that you should be aware of: the default location for feature files has changed from the src/test/features directory to the classpath. This is required as running as a test framework only has access to the test classpath. Features should therefore now live under src/test/resources. It is possible to change this back to another location by overriding the cucumberFeaturesLocation setting, but if you change this to anything other than the classpath then the 'test' task will not be able to find features.
88

99
## Overview ##
1010
Provides the ability to run Cucumber-jvm within the SBT environment. Originally based on the [cuke4duke-sbt-plugin](https://github.com/rubbish/cuke4duke-sbt-plugin) by rubbish and my original implementation for SBT 0.7.x. Specifics for this release:
@@ -49,6 +49,24 @@ It is also possible to filter exactly which features get executed by using the t
4949
test-only mypackage.CucumberSuite -- @demo
5050
test-only mypackage.CucumberSuite -- "User admin"
5151

52+
## Usage - Integration Test Framework ##
53+
Install the plugin and additional integration test framework integration (see later). Feature files MUST go in the 'src/it/resources' directory as only the classpath is visible to test frameworks. Step definitions go in 'src/it/scala'.
54+
55+
There must also be present somewhere in the test code the following class:
56+
57+
class CucumberSuite extends templemore.sbt.cucumber.RunCucumber
58+
59+
This is required to trigger cucumber to run (as SBT only runs tests that extends a specific base class or have a specific annotation). There MUST only be one instance of a class extending RunCucumber in the test code as we only want cucumber to be executed once! Finally from the sbt console call the task:
60+
61+
it:test
62+
63+
Note that none of the configuration options apply when running via a test framework. This is because the SBT integration test integration does not allow any access to these settings. Cucumber will be executed with pretty output to the console, searching the classpath from its root for features and executing all tests found in packages.
64+
65+
It is also possible to filter exactly which features get executed by using the test-only task. To do this, specify the CucumberSuite that you defined above as the test to run and then use either the tag or name approach already described as the test arguments:
66+
67+
it:test-only mypackage.CucumberSuite -- @demo
68+
it:test-only mypackage.CucumberSuite -- "User admin"
69+
5270
## Writing Features ##
5371
Features are written in text format and are placed in .feature files inside the 'src/test/resources' directory. For more info on writing features please see the [Cucumber](http://cukes.info) website.
5472
For example:
@@ -102,7 +120,7 @@ To install the cucumber plugin, add entries to the build plugins file (project/p
102120

103121
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
104122

105-
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0")
123+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")
106124

107125
### Basic Configuration ###
108126
To add the cucumber plugin settings to a basic project, just add the following to the build.sbt file:
@@ -142,6 +160,17 @@ If you wish to support cucumber running as a test framework (via the test task)
142160
settings = Defaults.defaultSettings ++
143161
CucumberPlugin.cucumberSettingsWithTestPhaseIntegration)
144162

163+
#### Running as an integration test framework ####
164+
If you wish to support cucumber running as an integration test framework (via the it:test task) then use this alternative settings group instead:
165+
166+
lazy val myProject = Project ("my-project", file ("."),
167+
settings = Defaults.defaultSettings ++
168+
CucumberPlugin.cucumberSettingsWithIntegrationTestPhaseIntegration)
169+
.configs(IntegrationTest)
170+
.settings(Defaults.itSettings : _*)
171+
172+
This will ensure the necessary jars and test frameworks are installed in the IntegrationTest config as opposed to the normal Test config. For more information about setting up an IntegrationTest config see the testProjects/integrationTestIntegrationProject or http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing.
173+
145174
## Customisation ##
146175
The plugin supports a number of customisations and settings. Note that these setting customisations only apply to running using the standalone 'cucumber' task. Running cucumber as a test framework does not support any customisation options.
147176

@@ -184,6 +213,11 @@ Requests for features can be posted to the issues list or emailed to the author.
184213

185214
## Release History ##
186215

216+
### 0.7.1 ###
217+
218+
Fix for issue #15. The templemore repository is now added as a resolver to the project when the plugin is added.
219+
Fix for issue #14. It is now possible to run cucumber within the IntegrationTest config.
220+
187221
### 0.7.0 ###
188222

189223
Significant refactor to support running cucumber via the standalone 'cucumber' task or integrated as test framework that can run as part of the standard SBT 'test' task.

Diff for: plugin/src/main/scala/templemore/sbt/cucumber/CucumberPlugin.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import templemore.sbt.util._
1010
*/
1111
object CucumberPlugin extends Plugin with Integration {
1212

13-
private val projectVersion = "0.7.0"
13+
private val projectVersion = "0.7.1"
1414

1515
type LifecycleCallback = () => Unit
1616

@@ -69,6 +69,7 @@ object CucumberPlugin extends Plugin with Integration {
6969
if ( scalaVersion.startsWith("2.10") ) "cucumber.api.cli.Main" else "cucumber.cli.Main"
7070

7171
val cucumberSettings: Seq[Setting[_]] = Seq(
72+
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo",
7273
libraryDependencies += "templemore" %% "sbt-cucumber-integration" % projectVersion % "test",
7374

7475
cucumber <<= inputTask(cucumberTask),
@@ -103,4 +104,9 @@ object CucumberPlugin extends Plugin with Integration {
103104
val cucumberSettingsWithTestPhaseIntegration = cucumberSettings ++ Seq(
104105
testFrameworks += new TestFramework("templemore.sbt.cucumber.CucumberFramework")
105106
)
107+
108+
val cucumberSettingsWithIntegrationTestPhaseIntegration = cucumberSettings ++ Seq(
109+
testFrameworks in IntegrationTest += new TestFramework("templemore.sbt.cucumber.CucumberFramework"),
110+
libraryDependencies += "templemore" %% "sbt-cucumber-integration" % projectVersion % "it"
111+
)
106112
}

Diff for: project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Keys._
44
object Settings {
55
val buildOrganization = "templemore"
66
val buildScalaVersion = "2.9.2"
7-
val buildVersion = "0.7.0"
7+
val buildVersion = "0.7.1"
88

99
val buildSettings = Defaults.defaultSettings ++
1010
Seq (organization := buildOrganization,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
target
3+
project/boot
4+
project/target
5+
project/plugins/target
6+
project/plugins/project
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sbt._
2+
import Keys._
3+
import templemore.sbt.cucumber.CucumberPlugin
4+
5+
object BuildSettings {
6+
val buildOrganization = "templemore"
7+
val buildScalaVersion = "2.9.2"
8+
val buildVersion = "0.7.1"
9+
10+
val buildSettings = Defaults.defaultSettings ++
11+
Seq (organization := buildOrganization,
12+
scalaVersion := buildScalaVersion,
13+
version := buildVersion)
14+
15+
val cucumberSettings = CucumberPlugin.cucumberSettingsWithIntegrationTestPhaseIntegration ++
16+
Seq(CucumberPlugin.cucumberHtmlReport := true,
17+
CucumberPlugin.cucumberPrettyReport := true)
18+
}
19+
20+
object Dependencies {
21+
22+
val scalaTest = "org.scalatest" %% "scalatest" % "1.7.2" % "it"
23+
}
24+
25+
object TestProjectBuild extends Build {
26+
import Dependencies._
27+
import BuildSettings._
28+
29+
lazy val integrationTestProject = Project ("integration-test-project", file ("."),
30+
settings = buildSettings ++ cucumberSettings ++ Seq (libraryDependencies += scalaTest))
31+
.configs(IntegrationTest)
32+
.settings(Defaults.itSettings : _*)
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.12.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
2+
3+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")
4+
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@example-jar
2+
Feature: Cucumber in Jar Project
3+
In order to implement BDD in my Scala project
4+
As a developer
5+
I want to be able to run Cucumber from with SBT
6+
7+
Scenario: Execute feature in a Jar Project
8+
Given an SBT project
9+
When the cucumber task is called
10+
Then Cucumber is executed against the features and step definitions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package test
2+
3+
import cucumber.runtime.{EN, ScalaDsl}
4+
import org.scalatest.matchers.ShouldMatchers
5+
import templemore.sbt.cucumber.RunCucumber
6+
7+
class CucumberJarStepDefinitions extends ScalaDsl with EN with ShouldMatchers {
8+
9+
private var givenCalled = false
10+
private var whenCalled = false
11+
12+
Given("""^an SBT project$""") { () =>
13+
givenCalled = true
14+
}
15+
16+
When("""^the cucumber task is called$""") { () =>
17+
whenCalled = true
18+
}
19+
20+
Then("""^Cucumber is executed against the features and step definitions$""") { () =>
21+
givenCalled should be (true)
22+
whenCalled should be (true)
23+
}
24+
}
25+
26+
class CucumberSuite extends RunCucumber

Diff for: testProjects/multiModuleTestProject/project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import templemore.sbt.cucumber.CucumberPlugin
55
object BuildSettings {
66
val buildOrganization = "templemore"
77
val buildScalaVersion = "2.9.2"
8-
val buildVersion = "0.7.0"
8+
val buildVersion = "0.7.1"
99

1010
val buildSettings = Defaults.defaultSettings ++
1111
Seq (organization := buildOrganization,
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
resolvers += Resolver.file("Local Repo", file((Path.userHome / ".m2" / "repository").toString))
22

3-
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0")
3+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")

Diff for: testProjects/testIntegrationProject/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "test-project"
22

3-
version := "0.7.0"
3+
version := "0.7.1"
44

55
organization := "templemore"
66

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
22

3-
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0")
3+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")
44

55

Diff for: testProjects/testProject/project/plugin.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
22

3-
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0")
3+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")
44

55

Diff for: testProjects/testProject2_10/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "test-project2_10"
22

3-
version := "0.7.0"
3+
version := "0.7.1"
44

55
organization := "templemore"
66

Diff for: testProjects/testProject2_10/project/plugin.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
22

3-
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0")
3+
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.1")

0 commit comments

Comments
 (0)