cucumber 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,224 +0,0 @@
1
- require 'erb'
2
- CUCUMBER = File.dirname(__FILE__) + '/../../../bin/cucumber'
3
-
4
- # TODO: Move all of this (except the ruby stepdef specific stepdefs) into cucumber-features
5
- # This way all Cucumber implementations can use Aruba/Cucumber 1.x to for testing, and have Aruba reports.
6
- module CucumberCoreHelpers
7
- def scenario_with_steps(scenario_name, steps)
8
- write_file("features/a_feature.feature", <<-EOF)
9
- Feature: A feature
10
- Scenario: #{scenario_name}
11
- #{steps.gsub(/^/, ' ')}
12
- EOF
13
- end
14
-
15
- def write_feature(feature)
16
- write_file("features/a_feature.feature", feature)
17
- end
18
-
19
- def write_passing_mapping(step_name)
20
- erb = ERB.new(<<-EOF, nil, '-')
21
- Given /<%= step_name -%>/ do
22
- # ARUBA_IGNORE_START
23
- File.open("<%= step_file(step_name) %>", "w")
24
- # ARUBA_IGNORE_END
25
- end
26
- EOF
27
- append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
28
- end
29
-
30
- def write_pending_mapping(step_name)
31
- erb = ERB.new(<<-EOF, nil, '-')
32
- Given /<%= step_name -%>/ do
33
- # ARUBA_IGNORE_START
34
- File.open("<%= step_file(step_name) %>", "w")
35
- # ARUBA_IGNORE_END
36
- pending
37
- end
38
- EOF
39
- append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
40
- end
41
-
42
- def write_failing_mapping(step_name)
43
- erb = ERB.new(<<-EOF, nil, '-')
44
- Given /<%= step_name -%>/ do
45
- # ARUBA_IGNORE_START
46
- File.open("<%= step_file(step_name) %>", "w")
47
- # ARUBA_IGNORE_END
48
- raise "bang!"
49
- end
50
- EOF
51
- append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
52
- end
53
-
54
- def write_calculator_code
55
- code = <<-EOF
56
- # http://en.wikipedia.org/wiki/Reverse_Polish_notation
57
- class RpnCalculator
58
- def initialize
59
- @stack = []
60
- end
61
-
62
- def push(arg)
63
- if(%w{- + * /}.index(arg))
64
- y, x = @stack.pop(2)
65
- push(x.__send__(arg, y))
66
- else
67
- @stack.push(arg)
68
- end
69
- end
70
-
71
- def PI
72
- push(Math::PI)
73
- end
74
-
75
- def value
76
- @stack[-1]
77
- end
78
- end
79
- EOF
80
- write_file("lib/rpn_calculator.rb", code)
81
- end
82
-
83
- def write_mappings_for_calculator
84
- write_file("features/support/env.rb", "$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')\n")
85
- mapping_code = <<-EOF
86
- require 'rpn_calculator'
87
-
88
- Given /^a calculator$/ do
89
- @calc = RpnCalculator.new
90
- end
91
-
92
- When /^the calculator computes PI$/ do
93
- @calc.PI
94
- end
95
-
96
- When /^the calculator adds up ([\\d\\.]+) and ([\\d\\.]+)$/ do |n1, n2|
97
- @calc.push(n1.to_f)
98
- @calc.push(n2.to_f)
99
- @calc.push('+')
100
- end
101
-
102
- When /^the calculator adds up "([^"]*)" and "([^"]*)"$/ do |n1, n2|
103
- @calc.push(n1.to_i)
104
- @calc.push(n2.to_i)
105
- @calc.push('+')
106
- end
107
-
108
- When /^the calculator adds up "([^"]*)", "([^"]*)" and "([^"]*)"$/ do |n1, n2, n3|
109
- @calc.push(n1.to_i)
110
- @calc.push(n2.to_i)
111
- @calc.push(n3.to_i)
112
- @calc.push('+')
113
- @calc.push('+')
114
- end
115
-
116
- When /^the calculator adds up the following numbers:$/ do |numbers|
117
- pushed = 0
118
- numbers.split("\\n").each do |n|
119
- @calc.push(n.to_i)
120
- pushed +=1
121
- @calc.push('+') if pushed > 1
122
- end
123
- end
124
-
125
- Then /^the calculator returns PI$/ do
126
- @calc.value.to_f.should be_within(0.00001).of(Math::PI)
127
- end
128
-
129
- Then /^the calculator returns "([^"]*)"$/ do |expected|
130
- @calc.value.to_f.should be_within(0.00001).of(expected.to_f)
131
- end
132
-
133
- Then /^the calculator does not return ([\\d\\.]+)$/ do |unexpected|
134
- @calc.value.to_f.should_not be_within(0.00001).of(unexpected.to_f)
135
- end
136
-
137
- EOF
138
- write_file("features/step_definitions/calculator_mappings.rb", mapping_code)
139
- end
140
-
141
- def step_file(pattern)
142
- pattern.gsub(/ /, '_') + '.step'
143
- end
144
-
145
- def run_scenario(scenario_name)
146
- run_simple "#{CUCUMBER} features/a_feature.feature --name '#{scenario_name}'", false
147
- end
148
-
149
- def run_feature
150
- run_simple "#{CUCUMBER} features/a_feature.feature", false
151
- end
152
-
153
- def assert_skipped(pattern)
154
- if File.exist?(File.join(current_dir, step_file(pattern)))
155
- raise "#{pattern} was not skipped"
156
- end
157
- end
158
- end
159
-
160
- World(CucumberCoreHelpers)
161
-
162
- Given /^a scenario "([^"]*)" with:$/ do |scenario_name, steps|
163
- @scenario_name = scenario_name
164
- scenario_with_steps(scenario_name, steps)
165
- end
166
-
167
- Given /^the following feature:$/ do |feature|
168
- write_feature(feature)
169
- end
170
-
171
- Given /^the step "([^"]*)" has a passing mapping$/ do |step_name|
172
- write_passing_mapping(step_name)
173
- end
174
-
175
- Given /^the step "([^"]*)" has a pending mapping$/ do |step_name|
176
- write_pending_mapping(step_name)
177
- end
178
-
179
- Given /^the step "([^"]*)" has a failing mapping$/ do |step_name|
180
- write_failing_mapping(step_name)
181
- end
182
-
183
- When /^Cucumber executes the scenario "([^"]*)"$/ do |scenario_name|
184
- run_scenario(scenario_name)
185
- end
186
-
187
- When /^Cucumber runs the feature$/ do
188
- run_feature
189
- end
190
-
191
- When /^Cucumber runs the scenario with steps for a calculator$/ do
192
- write_calculator_code
193
- write_mappings_for_calculator
194
- run_scenario(@scenario_name)
195
- end
196
-
197
- Then /^the scenario passes$/ do
198
- assert_partial_output("1 scenario (1 passed)", all_output)
199
- assert_success true
200
- end
201
-
202
- Then /^the scenario fails$/ do
203
- assert_partial_output("1 scenario (1 failed)", all_output)
204
- assert_success false
205
- end
206
-
207
- Then /^the scenario is pending$/ do
208
- assert_partial_output("1 scenario (1 pending)", all_output)
209
- assert_success true
210
- end
211
-
212
- Then /^the scenario is undefined$/ do
213
- assert_partial_output("1 scenario (1 undefined)", all_output)
214
- assert_success true
215
- end
216
-
217
- Then /^the step "([^"]*)" is skipped$/ do |pattern|
218
- assert_skipped(pattern)
219
- end
220
-
221
- Then /^the feature passes$/ do
222
- assert_no_partial_output("failed", all_output)
223
- assert_success true
224
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
- require 'cucumber/step_mother'
3
- require 'cucumber/ast'
4
- require 'cucumber/rb_support/rb_language'
5
-
6
- module Cucumber
7
- module Ast
8
- describe Scenario do
9
- before do
10
- @step_mother = Cucumber::Runtime.new
11
- @step_mother.load_programming_language('rb')
12
- @dsl = Object.new
13
- @dsl.extend(Cucumber::RbSupport::RbDsl)
14
-
15
- $x = $y = nil
16
- @dsl.Given /y is (\d+)/ do |n|
17
- $y = n.to_i
18
- end
19
- @visitor = TreeWalker.new(@step_mother)
20
- end
21
-
22
- it "should skip steps when previous is not passed" do
23
- scenario = Scenario.new(
24
- background=nil,
25
- comment=Comment.new(""),
26
- tags=Tags.new(98, []),
27
- line=99,
28
- keyword="",
29
- title="",
30
- description="",
31
- steps=[
32
- Step.new(7, "Given", "this is missing"),
33
- Step.new(8, "Given", "y is 5")
34
- ]
35
- )
36
- scenario.feature = mock('feature').as_null_object
37
- @visitor.visit_feature_element(scenario)
38
-
39
- $y.should == nil
40
- end
41
-
42
- end
43
- end
44
- end