-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
cucumber_java_mappings.rb
104 lines (87 loc) · 2.55 KB
/
cucumber_java_mappings.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'erb'
module CucumberJavaMappings
def features_dir
"src/test/resources"
end
def run_scenario(scenario_name)
write_pom
write_test_unit_classes
run_simple "mvn test", false
end
def write_pom
write_file('pom.xml', <<-EOF)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cucumber</groupId>
<artifactId>parent</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>0.4.3-SNAPSHOT</version>
</parent>
<artifactId>cucumber-picocontainer-test</artifactId>
<version>0.4.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber: PicoContainer Test</name>
<dependencies>
<dependency>
<groupId>cucumber</groupId>
<artifactId>picocontainer</artifactId>
<version>0.4.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
EOF
end
@@mappings_counter = 1
def write_passing_mapping(step_name)
erb = ERB.new(<<-EOF, nil, '-')
package cucumber.test;
import cucumber.annotation.EN.Given;
public class Mappings<%= @@mappings_counter %> {
@Given("<%= step_name -%>")
public void <%= step_name.gsub(/ /, '_') -%>() {
// ARUBA_IGNORE_START
try {
new java.io.FileWriter("<%= step_file(step_name) %>");
} catch(java.io.IOException e) {
throw new RuntimeException(e);
}
// ARUBA_IGNORE_END
}
}
EOF
write_file("src/test/java/cucumber/test/Mappings#{@@mappings_counter}.java", erb.result(binding))
@@mappings_counter += 1
end
def write_test_unit_classes
features = in_current_dir do
Dir.chdir(features_dir) do
Dir["**/*.feature"]
end
end
features.each do |feature|
class_name = File.basename(feature).match(/(.*)\.feature$/)[1] + "_Test"
write_file("src/test/java/cucumber/test/#{class_name}.java", <<-EOF)
package cucumber.test;
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@Feature("#{feature}")
public class #{class_name} {}
EOF
end
end
def assert_passing_scenario
2 tests because we have 2 steps
assert_partial_output("Tests run: 2, Failures: 0, Errors: 0, Skipped: 0", all_output)
assert_success true
end
end
World(CucumberJavaMappings)
Before do
@aruba_timeout_seconds = 10
end