cucumber-java 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2009-03-25
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
@@ -0,0 +1,14 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.textile
4
+ README.txt
5
+ Rakefile
6
+ examples/simple/README.textile
7
+ examples/simple/features/demo.feature
8
+ examples/simple/features/support/env.rb
9
+ examples/simple/pom.xml
10
+ examples/simple/src/main/java/simple/StuffSteps.java
11
+ lib/cucumber-java-0.0.1.jar
12
+ lib/cucumber/java.rb
13
+ lib/cucumber/java/version.rb
14
+ pom.xml
@@ -0,0 +1,70 @@
1
+ h1. Have a Cuke, Duke
2
+
3
+ Cucumber runs on Java! This gem lets you write Cucumber steps in pure Java. Example:
4
+
5
+ <pre>
6
+ package simple;
7
+
8
+ import java.util.Map;
9
+ import java.util.HashMap;
10
+ import cucumber.*;
11
+ import static org.junit.Assert.assertEquals;
12
+
13
+ public class StuffSteps {
14
+ private final Map<String,String> cukes = new HashMap<String,String>();
15
+
16
+ @Given("I have (\\d+) (.*) cukes")
17
+ public void iHaveNCukes(String n, String color) {
18
+ this.cukes.put(color, n);
19
+ }
20
+
21
+ @When("I add a table")
22
+ public void iAddATable(Table table) {
23
+ Map<String,String> hash = table.hashes().get(0);
24
+ assertEquals("1", hash.get("a"));
25
+ assertEquals("2", hash.get("b"));
26
+ }
27
+
28
+ @Then("I should have (\\d+) (.*) cukes")
29
+ public void iShouldHaveNCukes(String n, String color) {
30
+ if(!n.equals(cukes.get(color))) {
31
+ throw new RuntimeException("Expected " + n + ", got " + cukes.get(color));
32
+ }
33
+ }
34
+
35
+ public void thisIsNotAStep() {}
36
+ }
37
+ </pre>
38
+
39
+ Check out the examples for more details.
40
+
41
+ h2. Building the cucumber-java gem
42
+
43
+ This is for hackers. If you just want to use Cucumber with Java, head straight to
44
+ the examples.
45
+
46
+ h3. Install Maven
47
+
48
+ You can grab it "here":http://maven.apache.org/
49
+
50
+ h3. Install JRuby
51
+
52
+ You can grab it "here":http://jruby.org/
53
+ Make sure you get 1.2.0 or later.
54
+
55
+ h3. Install Hoe
56
+
57
+ This gem is needed to build the Cucumber Java gem
58
+
59
+ <pre>
60
+ jruby -S gem install hoe --no-rdoc --no-ri
61
+ </pre>
62
+
63
+ h3. Build and install the gem
64
+
65
+ <pre>
66
+ jruby -S rake gem
67
+ jruby -S gem install pkg/cucumber-java --no-rdoc --no-ri
68
+ </pre>
69
+
70
+ Now head to the simple example and run it. It serves well as a testbed.
@@ -0,0 +1 @@
1
+ See README.textile
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ ENV['NODOT'] = 'true' # We don't want class diagrams in RDoc
3
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
+ task :gem => :jar
5
+ require 'cucumber/java/version'
6
+ require 'hoe'
7
+
8
+ AUTHOR = 'Aslak Hellesøy' # can also be an array of Authors
9
+ EMAIL = "aslak.hellesoy@gmail.com"
10
+ DESCRIPTION = "Cucumber for Java"
11
+ GEM_NAME = 'cucumber-java' # what ppl will type to install your gem
12
+ HOMEPATH = "http://cukes.info"
13
+ RUBYFORGE_PROJECT = 'rspec'
14
+
15
+ @config_file = "~/.rubyforge/user-config.yml"
16
+ @config = nil
17
+ RUBYFORGE_USERNAME = "aslak_hellesoy"
18
+ def rubyforge_username
19
+ unless @config
20
+ begin
21
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
22
+ rescue
23
+ puts <<-EOS
24
+ ERROR: No rubyforge config file found: #{@config_file}
25
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
26
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
27
+ EOS
28
+ exit
29
+ end
30
+ end
31
+ RUBYFORGE_USERNAME.replace @config["username"]
32
+ end
33
+
34
+ RDOC_OPTS = ['--quiet', '--title', 'Cucumber documentation',
35
+ "--opname", "index.html",
36
+ "--line-numbers",
37
+ "--main", "README.textile",
38
+ "--inline-source"]
39
+
40
+ class Hoe
41
+ def extra_deps
42
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
43
+ @extra_deps
44
+ end
45
+ end
46
+
47
+ # Generate all the Rake tasks
48
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
49
+ $hoe = Hoe.new(GEM_NAME, Cucumber::Java::VERSION::STRING) do |p|
50
+ p.developer(AUTHOR, EMAIL)
51
+ p.description = DESCRIPTION
52
+ p.summary = DESCRIPTION
53
+ p.url = HOMEPATH
54
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
55
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store', '**/*.class'] #An array of file patterns to delete on clean.
56
+
57
+ # == Optional
58
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
59
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
60
+ p.extra_deps = [
61
+ ['cucumber', '>= 0.2.2']
62
+ ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ $hoe.rsync_args = '-av --delete --ignore-errors'
72
+
73
+ # Hoe gives us :default => :test, but we don't have Test::Unit tests.
74
+ Rake::Task[:default].clear_prerequisites rescue nil # For some super weird reason this fails for some...
75
+
76
+ task :jar do
77
+ sh 'mvn clean compile jar:jar'
78
+ mv "target/cucumber-java-#{Cucumber::Java::VERSION::STRING}.jar", 'lib'
79
+ sh 'mvn clean'
80
+ end
@@ -0,0 +1,56 @@
1
+ h1. Cucumber Java Simple example
2
+
3
+ This project is a very basic example that illustrates how to use Cucumber with
4
+ Java, writing step definitions in pure Java.
5
+
6
+ h2. Prerequisites
7
+
8
+ * Install Maven
9
+ * Install JRuby (1.2.0 or newer)
10
+ * jruby -S gem install cucumber-java
11
+ * Download PicoContainer and JUnit jars
12
+ ** See features/support/env.rb for details. You may have to change the paths there depending on where you put jars.
13
+
14
+ h2. Running it
15
+
16
+ h3. Build the java code
17
+
18
+ <pre>
19
+ mvn clean compile jar:jar
20
+ </pre>
21
+
22
+ You will get an error from Maven complaining that the cucumber-java jar file doesn't
23
+ exist. (You'll need that jar if you want to use Cucumber tables in Java). Just do what Maven
24
+ says - the cucumber jar can be found inside your cucumber-java gem, for example:
25
+
26
+ <pre>
27
+ mvn install:install-file -DgroupId=cucumber -DartifactId=cucumber-java -Dversion=0.0.1 -Dpackaging=jar -Dfile=/usr/local/jruby/lib/ruby/gems/1.8/gems/cucumber-java-0.0.1/lib/cucumber-java-0.0.1.jar
28
+ </pre>
29
+
30
+ Now, just try building again.
31
+
32
+ h3. Run the features:
33
+
34
+ <pre>
35
+ jruby -S cucumber features
36
+ </pre>
37
+
38
+ Try to make the features fail by modifying the java code or the feature file - check out the output...
39
+
40
+ See the "Cucumber Wiki":http://wiki.github.com/aslakhellesoy/cucumber for more info.
41
+
42
+ h2. Hacking
43
+
44
+ If you want to hack on the cucumber-java gem and use this example as a testbed, it's easier to run off
45
+ cucumber and cucumber-java as "source" instead of gems.
46
+ Here is what I do:
47
+
48
+ <pre>
49
+ jruby -I../../lib PATH_TO_CUCUMBER_SRC/bin/cucumber features
50
+ </pre>
51
+
52
+ h2. TODO
53
+
54
+ * Make it possible to run Cucumber from Maven
55
+ ** Make maven launch JRuby with a classpath that includes picocontainer, junit, step defnitions, code to test, any other deps.
56
+ ** Remove all of the jar requires from env.rb
@@ -0,0 +1,8 @@
1
+ Feature: Simple
2
+
3
+ Scenario: 3 cukes
4
+ Given I have 3 green cukes
5
+ When I add a table
6
+ |a|b|
7
+ |1|2|
8
+ Then I should have 3 green cukes
@@ -0,0 +1,15 @@
1
+ # Cucumber Java depends on PicoContainer to instantiate classes with Step definitions
2
+ require File.expand_path('~/.m2/repository/org/picocontainer/picocontainer/2.8/picocontainer-2.8.jar')
3
+
4
+ # Load Cucumber Java support
5
+ require 'cucumber/java'
6
+
7
+ # Load JUnit - our Step definitions use it for assertions
8
+ require File.expand_path('~/.m2/repository/junit/junit/4.4/junit-4.4.jar')
9
+
10
+ # Load our step definitions
11
+ require File.expand_path(File.dirname(__FILE__) + '/../../target/cucumber-simple-example-1.0.0.jar')
12
+
13
+ # Register our steps definitions.
14
+ import 'simple.StuffSteps'
15
+ register_steps(StuffSteps)
@@ -0,0 +1,48 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>cucumber</groupId>
7
+ <artifactId>cucumber-simple-example</artifactId>
8
+ <packaging>jar</packaging>
9
+ <version>1.0.0</version>
10
+ <name>Cucumber Java Support</name>
11
+ <url>http://cukes.info/</url>
12
+
13
+ <repositories>
14
+ <repository>
15
+ <id>codehaus</id>
16
+ <url>http://repository.codehaus.org</url>
17
+ </repository>
18
+ </repositories>
19
+
20
+ <dependencies>
21
+ <dependency>
22
+ <groupId>cucumber</groupId>
23
+ <artifactId>cucumber-java</artifactId>
24
+ <version>0.0.1</version>
25
+ </dependency>
26
+ <dependency>
27
+ <groupId>junit</groupId>
28
+ <artifactId>junit</artifactId>
29
+ <version>4.4</version>
30
+ </dependency>
31
+ </dependencies>
32
+
33
+ <build>
34
+ <pluginManagement>
35
+ <plugins>
36
+ <plugin>
37
+ <groupId>org.apache.maven.plugins</groupId>
38
+ <artifactId>maven-compiler-plugin</artifactId>
39
+ <version>2.0.2</version>
40
+ <configuration>
41
+ <source>1.5</source>
42
+ <target>1.5</target>
43
+ </configuration>
44
+ </plugin>
45
+ </plugins>
46
+ </pluginManagement>
47
+ </build>
48
+ </project>
@@ -0,0 +1,30 @@
1
+ package simple;
2
+
3
+ import java.util.Map;
4
+ import java.util.HashMap;
5
+ import cucumber.*;
6
+ import static org.junit.Assert.assertEquals;
7
+
8
+ // TODO: This is just testing a Map. We should have some own code to test!!
9
+ public class StuffSteps {
10
+ private final Map<String,String> cukes = new HashMap<String,String>();
11
+
12
+ @Given("I have (\\d+) (.*) cukes")
13
+ public void iHaveNCukes(String n, String color) {
14
+ this.cukes.put(color, n);
15
+ }
16
+
17
+ @When("I add a table")
18
+ public void iAddATable(Table table) {
19
+ Map<String,String> hash = table.hashes().get(0);
20
+ assertEquals("1", hash.get("a"));
21
+ assertEquals("2", hash.get("b"));
22
+ }
23
+
24
+ @Then("I should have (\\d+) (.*) cukes")
25
+ public void iShouldHaveNCukes(String n, String color) {
26
+ assertEquals(n, cukes.get(color));
27
+ }
28
+
29
+ public void thisIsNotAStep() {}
30
+ }
@@ -0,0 +1,69 @@
1
+ require 'cucumber/java/version'
2
+ require "cucumber-java-#{Cucumber::Java::VERSION::STRING}.jar"
3
+ import 'cucumber.internal.StepDefinition'
4
+ import 'cucumber.internal.StepMother'
5
+ import 'cucumber.Table'
6
+
7
+ module Cucumber
8
+ module Ast
9
+ class Table
10
+ include ::Java::Cucumber::Table
11
+ end
12
+ end
13
+
14
+ module PureJava
15
+ module StepDefinitionExtras
16
+ def regexp
17
+ Regexp.new(getRegexpString)
18
+ end
19
+
20
+ def invoke(world, args)
21
+ begin
22
+ invokeOnTarget(args)
23
+ rescue Exception => e
24
+ java_exception_to_ruby_exception(e)
25
+ raise(java_exception_to_ruby_exception(e))
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def java_exception_to_ruby_exception(java_exception)
32
+ bt = java_exception.backtrace
33
+ Exception.cucumber_strip_backtrace!(bt, nil, nil)
34
+ exception = JavaException.new(java_exception.message)
35
+ exception.set_backtrace(bt)
36
+ exception
37
+ end
38
+
39
+ class JavaException < Exception
40
+ end
41
+ end
42
+
43
+ def self.extended(base)
44
+ base.instance_eval do
45
+ @__cucumber_java_step_mother = ::Java::CucumberInternal::StepMother.new
46
+ end
47
+ end
48
+
49
+ def register_steps(steps_class)
50
+ @__cucumber_java_step_mother.add(steps_class)
51
+ end
52
+
53
+ def new_world!
54
+ @__cucumber_java_step_mother.newWorld
55
+ end
56
+
57
+ def step_definitions
58
+ @__cucumber_java_step_mother.getStepDefinitions
59
+ end
60
+ end
61
+ end
62
+ extend(Cucumber::PureJava)
63
+
64
+ class Java::CucumberInternal::StepDefinition
65
+ include Cucumber::StepDefinitionMethods
66
+ include Cucumber::PureJava::StepDefinitionExtras
67
+ end
68
+
69
+ Exception::CUCUMBER_FILTER_PATTERNS.unshift(/^org\/jruby|^cucumber\/java|^org\/junit|^java\/|^sun\/|^\$_dot_dot_/)
@@ -0,0 +1,13 @@
1
+ module Cucumber #:nodoc:
2
+ module Java #:nodoc:
3
+ # IMPORTANT - KEEP IN SYNC WITH pom.xml version and Manifest.txt
4
+ class VERSION #:nodoc:
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ TINY = 1
8
+ PATCH = nil # Set to nil for official release
9
+
10
+ STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
11
+ end
12
+ end
13
+ end
data/pom.xml ADDED
@@ -0,0 +1,54 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>cucumber</groupId>
7
+ <artifactId>cucumber-java</artifactId>
8
+ <packaging>jar</packaging>
9
+ <!-- IMPORTANT - KEEP IN SYNC WITH version.rb version and Manifest.txt -->
10
+ <version>0.0.1</version>
11
+ <name>Cucumber Java Support</name>
12
+ <url>http://cukes.info/</url>
13
+
14
+ <repositories>
15
+ <repository>
16
+ <id>codehaus</id>
17
+ <url>http://repository.codehaus.org</url>
18
+ </repository>
19
+ </repositories>
20
+
21
+ <dependencies>
22
+ <dependency>
23
+ <groupId>org.picocontainer</groupId>
24
+ <artifactId>picocontainer</artifactId>
25
+ <version>2.8</version>
26
+ </dependency>
27
+ <dependency>
28
+ <groupId>junit</groupId>
29
+ <artifactId>junit</artifactId>
30
+ <version>4.4</version>
31
+ </dependency>
32
+ <dependency>
33
+ <groupId>org.jruby</groupId>
34
+ <artifactId>jruby</artifactId>
35
+ <version>1.2.0</version>
36
+ </dependency>
37
+ </dependencies>
38
+
39
+ <build>
40
+ <pluginManagement>
41
+ <plugins>
42
+ <plugin>
43
+ <groupId>org.apache.maven.plugins</groupId>
44
+ <artifactId>maven-compiler-plugin</artifactId>
45
+ <version>2.0.2</version>
46
+ <configuration>
47
+ <source>1.5</source>
48
+ <target>1.5</target>
49
+ </configuration>
50
+ </plugin>
51
+ </plugins>
52
+ </pluginManagement>
53
+ </build>
54
+ </project>
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-java
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Aslak Helles\xC3\xB8y"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-25 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cucumber
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.3
34
+ version:
35
+ description: Cucumber for Java
36
+ email:
37
+ - aslak.hellesoy@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.txt
46
+ files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.textile
50
+ - README.txt
51
+ - Rakefile
52
+ - examples/simple/README.textile
53
+ - examples/simple/features/demo.feature
54
+ - examples/simple/features/support/env.rb
55
+ - examples/simple/pom.xml
56
+ - examples/simple/src/main/java/simple/StuffSteps.java
57
+ - lib/cucumber-java-0.0.1.jar
58
+ - lib/cucumber/java.rb
59
+ - lib/cucumber/java/version.rb
60
+ - pom.xml
61
+ has_rdoc: true
62
+ homepage: http://cukes.info
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: rspec
84
+ rubygems_version: 1.3.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Cucumber for Java
88
+ test_files: []
89
+