kosmas58-cucumber 0.3.96 → 0.3.97
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +22 -3
- data/License.txt +2 -0
- data/Manifest.txt +9 -5
- data/config/hoe.rb +1 -0
- data/examples/i18n/Rakefile +5 -3
- data/examples/i18n/fi/features/yhteenlasku.feature +5 -4
- data/examples/python/features/step_definitions/fib_steps.py +3 -0
- data/examples/python/features/support/env.rb +21 -21
- data/gem_tasks/contributors.rake +8 -0
- data/gem_tasks/features.rake +1 -0
- data/gem_tasks/sdoc.rake +7 -0
- data/lib/README.rdoc +12 -0
- data/lib/cucumber/ast/background.rb +1 -1
- data/lib/cucumber/ast/comment.rb +1 -1
- data/lib/cucumber/ast/examples.rb +9 -4
- data/lib/cucumber/ast/feature.rb +1 -1
- data/lib/cucumber/ast/feature_element.rb +1 -1
- data/lib/cucumber/ast/features.rb +1 -1
- data/lib/cucumber/ast/outline_table.rb +2 -2
- data/lib/cucumber/ast/py_string.rb +1 -1
- data/lib/cucumber/ast/scenario.rb +1 -1
- data/lib/cucumber/ast/scenario_outline.rb +8 -7
- data/lib/cucumber/ast/step.rb +1 -1
- data/lib/cucumber/ast/step_collection.rb +1 -1
- data/lib/cucumber/ast/step_invocation.rb +1 -1
- data/lib/cucumber/ast/table.rb +65 -45
- data/lib/cucumber/ast/tags.rb +2 -2
- data/lib/cucumber/ast/visitor.rb +6 -8
- data/lib/cucumber/broadcaster.rb +1 -1
- data/lib/cucumber/cli/language_help_formatter.rb +1 -1
- data/lib/cucumber/cli/main.rb +15 -52
- data/lib/cucumber/constantize.rb +1 -1
- data/lib/cucumber/core_ext/exception.rb +1 -1
- data/lib/cucumber/core_ext/instance_exec.rb +8 -3
- data/lib/cucumber/core_ext/proc.rb +1 -1
- data/lib/cucumber/core_ext/string.rb +1 -1
- data/lib/cucumber/feature_file.rb +4 -3
- data/lib/cucumber/filter.rb +2 -1
- data/lib/cucumber/formatter/ansicolor.rb +6 -5
- data/lib/cucumber/formatter/color_io.rb +2 -2
- data/lib/cucumber/formatter/console.rb +2 -0
- data/lib/cucumber/formatter/duration.rb +3 -0
- data/lib/cucumber/formatter/html.rb +1 -0
- data/lib/cucumber/formatter/junit.rb +1 -0
- data/lib/cucumber/formatter/ordered_xml_markup.rb +1 -1
- data/lib/cucumber/formatter/pretty.rb +18 -4
- data/lib/cucumber/formatter/profile.rb +1 -0
- data/lib/cucumber/formatter/progress.rb +1 -0
- data/lib/cucumber/formatter/rerun.rb +2 -0
- data/lib/cucumber/formatter/steps.rb +1 -0
- data/lib/cucumber/formatter/tag_cloud.rb +2 -1
- data/lib/cucumber/formatter/unicode.rb +1 -1
- data/lib/cucumber/formatter/usage.rb +1 -0
- data/lib/cucumber/language_support/language_methods.rb +34 -12
- data/lib/cucumber/language_support.rb +30 -0
- data/lib/cucumber/parser/feature.rb +81 -57
- data/lib/cucumber/parser/feature.tt +3 -3
- data/lib/cucumber/parser/natural_language.rb +1 -1
- data/lib/cucumber/parser/table.rb +3 -0
- data/lib/cucumber/parser/treetop_ext.rb +6 -5
- data/lib/cucumber/platform.rb +1 -2
- data/lib/cucumber/py_support/py_dsl.py +8 -0
- data/lib/cucumber/py_support/py_language.py +2 -0
- data/lib/cucumber/py_support/py_language.rb +68 -0
- data/lib/cucumber/rails/world.rb +2 -1
- data/lib/cucumber/rake/task.rb +13 -11
- data/lib/cucumber/rb_support/rb_dsl.rb +27 -15
- data/lib/cucumber/rb_support/rb_hook.rb +1 -2
- data/lib/cucumber/rb_support/rb_language.rb +57 -33
- data/lib/cucumber/rb_support/rb_step_definition.rb +42 -38
- data/lib/cucumber/rb_support/rb_world.rb +93 -0
- data/lib/cucumber/rspec_neuter.rb +3 -3
- data/lib/cucumber/step_match.rb +2 -2
- data/lib/cucumber/step_mother.rb +91 -65
- data/lib/cucumber/version.rb +1 -1
- data/lib/cucumber/webrat/element_locator.rb +3 -3
- data/rails_generators/cucumber/templates/cucumber.rake +2 -0
- data/rails_generators/cucumber/templates/en/webrat_steps.rb +4 -0
- data/spec/cucumber/ast/background_spec.rb +8 -1
- data/spec/cucumber/ast/scenario_outline_spec.rb +1 -0
- data/spec/cucumber/ast/table_spec.rb +10 -0
- data/spec/cucumber/cli/options_spec.rb +1 -1
- data/spec/cucumber/parser/feature_parser_spec.rb +4 -0
- data/spec/cucumber/rb_support/rb_step_definition_spec.rb +114 -0
- data/spec/cucumber/step_mother_spec.rb +29 -10
- data/spec/cucumber/treetop_parser/with_comments.feature +14 -1
- data/spec/cucumber/world/pending_spec.rb +1 -1
- metadata +21 -7
- data/gem_tasks/yard.rake +0 -8
- data/lib/cucumber/language_support/hook_methods.rb +0 -9
- data/lib/cucumber/world.rb +0 -89
- data/spec/cucumber/ast/visitor_spec.rb +0 -27
- data/spec/cucumber/step_definition_spec.rb +0 -102
data/lib/cucumber/step_mother.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'cucumber/constantize'
|
2
|
-
require 'cucumber/world'
|
3
3
|
require 'cucumber/core_ext/instance_exec'
|
4
4
|
require 'cucumber/parser/natural_language'
|
5
|
-
require 'cucumber/language_support/hook_methods'
|
6
5
|
require 'cucumber/language_support/language_methods'
|
7
6
|
require 'cucumber/language_support/step_definition_methods'
|
8
7
|
|
9
8
|
module Cucumber
|
9
|
+
# Raised when there is no matching StepDefinition for a step.
|
10
10
|
class Undefined < StandardError
|
11
11
|
attr_reader :step_name
|
12
12
|
|
@@ -28,7 +28,7 @@ module Cucumber
|
|
28
28
|
class Pending < StandardError
|
29
29
|
end
|
30
30
|
|
31
|
-
# Raised when a step matches 2 or more
|
31
|
+
# Raised when a step matches 2 or more StepDefinitions
|
32
32
|
class Ambiguous < StandardError
|
33
33
|
def initialize(step_name, step_definitions, used_guess)
|
34
34
|
message = "Ambiguous match of \"#{step_name}\":\n\n"
|
@@ -49,27 +49,61 @@ module Cucumber
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
# This is the
|
53
|
-
# from <tt>*_steps.rb</tt> files. This module is included right at the top-level
|
54
|
-
# so #register_step_definition (and more interestingly - its aliases) are
|
55
|
-
# available from the top-level.
|
52
|
+
# This is the meaty part of Cucumber that ties everything together.
|
56
53
|
class StepMother
|
57
54
|
include Constantize
|
58
55
|
|
59
|
-
attr_writer :options, :visitor
|
56
|
+
attr_writer :options, :visitor, :log
|
60
57
|
|
61
58
|
def initialize
|
59
|
+
@unsupported_programming_languages = []
|
62
60
|
@programming_languages = []
|
63
61
|
@language_map = {}
|
64
62
|
load_natural_language('en')
|
65
63
|
end
|
66
64
|
|
65
|
+
def load_plain_text_features(feature_files)
|
66
|
+
features = Ast::Features.new
|
67
|
+
|
68
|
+
log.debug("Features:\n")
|
69
|
+
feature_files.each do |f|
|
70
|
+
feature_file = FeatureFile.new(f)
|
71
|
+
feature = feature_file.parse(self, options)
|
72
|
+
if feature
|
73
|
+
features.add_feature(feature)
|
74
|
+
log.debug(" * #{f}\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
log.debug("\n")
|
78
|
+
features
|
79
|
+
end
|
80
|
+
|
81
|
+
def load_code_files(step_def_files)
|
82
|
+
log.debug("Code:\n")
|
83
|
+
step_def_files.each do |step_def_file|
|
84
|
+
load_code_file(step_def_file)
|
85
|
+
end
|
86
|
+
log.debug("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
def load_code_file(step_def_file)
|
90
|
+
if programming_language = programming_language_for(step_def_file)
|
91
|
+
log.debug(" * #{step_def_file}\n")
|
92
|
+
step_definitions = programming_language.step_definitions_for(step_def_file)
|
93
|
+
register_step_definitions(step_definitions)
|
94
|
+
else
|
95
|
+
log.debug(" * #{step_def_file} [NOT SUPPORTED]\n")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def register_step_definitions(step_definitions)
|
100
|
+
step_definitions.each{|step_definition| register_step_definition(step_definition)}
|
101
|
+
end
|
102
|
+
|
67
103
|
# Loads and registers programming language implementation.
|
68
104
|
# Instances are cached, so calling with the same argument
|
69
105
|
# twice will return the same instance.
|
70
106
|
#
|
71
|
-
# Raises an exception if the language can't be loaded.
|
72
|
-
#
|
73
107
|
def load_programming_language(ext)
|
74
108
|
return @language_map[ext] if @language_map[ext]
|
75
109
|
programming_language_class = constantize("Cucumber::#{ext.capitalize}Support::#{ext.capitalize}Language")
|
@@ -88,26 +122,16 @@ module Cucumber
|
|
88
122
|
Parser::NaturalLanguage.get(self, lang)
|
89
123
|
end
|
90
124
|
|
91
|
-
#
|
92
|
-
# or any other kind of object that implements the StepDefintion
|
93
|
-
# contract (API).
|
94
|
-
def register_step_definition(step_definition)
|
95
|
-
step_definitions.each do |already|
|
96
|
-
raise Redundant.new(already, step_definition) if already.same_regexp?(step_definition.regexp)
|
97
|
-
end
|
98
|
-
step_definitions << step_definition
|
99
|
-
step_definition
|
100
|
-
end
|
101
|
-
|
125
|
+
# Returns the options passed on the command line.
|
102
126
|
def options
|
103
127
|
@options ||= {}
|
104
128
|
end
|
105
129
|
|
106
|
-
def step_visited(step)
|
130
|
+
def step_visited(step) #:nodoc:
|
107
131
|
steps << step unless steps.index(step)
|
108
132
|
end
|
109
|
-
|
110
|
-
def steps(status = nil)
|
133
|
+
|
134
|
+
def steps(status = nil) #:nodoc:
|
111
135
|
@steps ||= []
|
112
136
|
if(status)
|
113
137
|
@steps.select{|step| step.status == status}
|
@@ -116,11 +140,11 @@ module Cucumber
|
|
116
140
|
end
|
117
141
|
end
|
118
142
|
|
119
|
-
def announce(msg)
|
143
|
+
def announce(msg) #:nodoc:
|
120
144
|
@visitor.announce(msg)
|
121
145
|
end
|
122
146
|
|
123
|
-
def scenarios(status = nil)
|
147
|
+
def scenarios(status = nil) #:nodoc:
|
124
148
|
@scenarios ||= []
|
125
149
|
if(status)
|
126
150
|
@scenarios.select{|scenario| scenario.status == status}
|
@@ -129,20 +153,7 @@ module Cucumber
|
|
129
153
|
end
|
130
154
|
end
|
131
155
|
|
132
|
-
def
|
133
|
-
hooks[phase.to_sym] << hook
|
134
|
-
hook
|
135
|
-
end
|
136
|
-
|
137
|
-
def hooks
|
138
|
-
@hooks ||= Hash.new {|hash, phase| hash[phase] = []}
|
139
|
-
end
|
140
|
-
|
141
|
-
def hooks_for(phase, scenario)
|
142
|
-
hooks[phase.to_sym].select{|hook| scenario.accept_hook?(hook)}
|
143
|
-
end
|
144
|
-
|
145
|
-
def step_match(step_name, formatted_step_name=nil)
|
156
|
+
def step_match(step_name, formatted_step_name=nil) #:nodoc:
|
146
157
|
matches = step_definitions.map { |d| d.step_match(step_name, formatted_step_name) }.compact
|
147
158
|
raise Undefined.new(step_name) if matches.empty?
|
148
159
|
matches = best_matches(step_name, matches) if matches.size > 1 && options[:guess]
|
@@ -150,7 +161,7 @@ module Cucumber
|
|
150
161
|
matches[0]
|
151
162
|
end
|
152
163
|
|
153
|
-
def best_matches(step_name, step_matches)
|
164
|
+
def best_matches(step_name, step_matches) #:nodoc:
|
154
165
|
no_groups = step_matches.select {|step_match| step_match.args.length == 0}
|
155
166
|
max_arg_length = step_matches.map {|step_match| step_match.args.length }.max
|
156
167
|
top_groups = step_matches.select {|step_match| step_match.args.length == max_arg_length }
|
@@ -166,31 +177,31 @@ module Cucumber
|
|
166
177
|
end
|
167
178
|
end
|
168
179
|
|
169
|
-
def clear!
|
180
|
+
def clear! #:nodoc:
|
170
181
|
step_definitions.clear
|
171
182
|
hooks.clear
|
172
183
|
steps.clear
|
173
184
|
scenarios.clear
|
174
185
|
end
|
175
186
|
|
176
|
-
def step_definitions
|
187
|
+
def step_definitions #:nodoc:
|
177
188
|
@step_definitions ||= []
|
178
189
|
end
|
179
190
|
|
180
|
-
def snippet_text(step_keyword, step_name, multiline_arg_class)
|
191
|
+
def snippet_text(step_keyword, step_name, multiline_arg_class) #:nodoc:
|
181
192
|
@programming_languages.map do |programming_language|
|
182
193
|
programming_language.snippet_text(step_keyword, step_name, multiline_arg_class)
|
183
194
|
end.join("\n")
|
184
195
|
end
|
185
196
|
|
186
|
-
def before_and_after(scenario, skip_hooks=false)
|
197
|
+
def before_and_after(scenario, skip_hooks=false) #:nodoc:
|
187
198
|
before(scenario) unless skip_hooks
|
188
199
|
yield scenario
|
189
200
|
after(scenario) unless skip_hooks
|
190
201
|
scenario_visited(scenario)
|
191
202
|
end
|
192
203
|
|
193
|
-
def register_adverbs(adverbs)
|
204
|
+
def register_adverbs(adverbs) #:nodoc:
|
194
205
|
@adverbs ||= []
|
195
206
|
@adverbs += adverbs
|
196
207
|
@adverbs.uniq!
|
@@ -198,22 +209,8 @@ module Cucumber
|
|
198
209
|
programming_language.alias_adverbs(@adverbs)
|
199
210
|
end
|
200
211
|
end
|
201
|
-
|
202
|
-
def begin_scenario
|
203
|
-
return if options[:dry_run]
|
204
|
-
@programming_languages.each do |programming_language|
|
205
|
-
programming_language.begin_scenario
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
def end_scenario
|
210
|
-
return if options[:dry_run]
|
211
|
-
@programming_languages.each do |programming_language|
|
212
|
-
programming_language.end_scenario
|
213
|
-
end
|
214
|
-
end
|
215
212
|
|
216
|
-
def before(scenario)
|
213
|
+
def before(scenario) #:nodoc:
|
217
214
|
return if options[:dry_run] || @current_scenario
|
218
215
|
@current_scenario = scenario
|
219
216
|
@programming_languages.each do |programming_language|
|
@@ -221,7 +218,7 @@ module Cucumber
|
|
221
218
|
end
|
222
219
|
end
|
223
220
|
|
224
|
-
def after(scenario)
|
221
|
+
def after(scenario) #:nodoc:
|
225
222
|
@current_scenario = nil
|
226
223
|
return if options[:dry_run]
|
227
224
|
@programming_languages.each do |programming_language|
|
@@ -229,7 +226,7 @@ module Cucumber
|
|
229
226
|
end
|
230
227
|
end
|
231
228
|
|
232
|
-
def after_step
|
229
|
+
def after_step #:nodoc:
|
233
230
|
return if options[:dry_run]
|
234
231
|
@programming_languages.each do |programming_language|
|
235
232
|
programming_language.execute_after_step(@current_scenario)
|
@@ -238,12 +235,41 @@ module Cucumber
|
|
238
235
|
|
239
236
|
private
|
240
237
|
|
241
|
-
|
238
|
+
# Registers a StepDefinition. This can be a Ruby StepDefintion,
|
239
|
+
# or any other kind of object that implements the StepDefintion
|
240
|
+
# contract (API).
|
241
|
+
def register_step_definition(step_definition)
|
242
|
+
step_definitions.each do |already|
|
243
|
+
raise Redundant.new(already, step_definition) if already.same_regexp?(step_definition.regexp)
|
244
|
+
end
|
245
|
+
step_definitions << step_definition
|
246
|
+
step_definition
|
247
|
+
end
|
248
|
+
|
249
|
+
def programming_language_for(step_def_file) #:nodoc:
|
250
|
+
if ext = File.extname(step_def_file)[1..-1]
|
251
|
+
return nil if @unsupported_programming_languages.index(ext)
|
252
|
+
begin
|
253
|
+
load_programming_language(ext)
|
254
|
+
rescue LoadError
|
255
|
+
@unsupported_programming_languages << ext
|
256
|
+
nil
|
257
|
+
end
|
258
|
+
else
|
259
|
+
nil
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def max_step_definition_length #:nodoc:
|
242
264
|
@max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
|
243
265
|
end
|
244
266
|
|
245
|
-
def scenario_visited(scenario)
|
267
|
+
def scenario_visited(scenario) #:nodoc:
|
246
268
|
scenarios << scenario unless scenarios.index(scenario)
|
247
269
|
end
|
270
|
+
|
271
|
+
def log
|
272
|
+
@log ||= Logger.new(STDOUT)
|
273
|
+
end
|
248
274
|
end
|
249
275
|
end
|
data/lib/cucumber/version.rb
CHANGED
@@ -55,7 +55,7 @@ module Webrat
|
|
55
55
|
end
|
56
56
|
|
57
57
|
module Locators
|
58
|
-
class ElementLocator < Locator
|
58
|
+
class ElementLocator < Locator #:nodoc:
|
59
59
|
def locate
|
60
60
|
Element.load(@session, table_element)
|
61
61
|
end
|
@@ -77,11 +77,11 @@ module Webrat
|
|
77
77
|
alias table_at element_at # Backwards compatibility with Cucumber
|
78
78
|
end
|
79
79
|
|
80
|
-
module Methods
|
80
|
+
module Methods #:nodoc:
|
81
81
|
delegate_to_session :element_at, :table_at
|
82
82
|
end
|
83
83
|
|
84
|
-
class Session
|
84
|
+
class Session #:nodoc:
|
85
85
|
def_delegators :current_scope, :element_at, :table_at
|
86
86
|
end
|
87
87
|
end
|
@@ -27,6 +27,10 @@ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
|
|
27
27
|
fill_in(field, :with => value)
|
28
28
|
end
|
29
29
|
|
30
|
+
When /^I fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
|
31
|
+
fill_in(field, :with => value)
|
32
|
+
end
|
33
|
+
|
30
34
|
# Use this to fill in an entire form with data from a table. Example:
|
31
35
|
#
|
32
36
|
# When I fill in the following:
|
@@ -10,7 +10,7 @@ module Cucumber
|
|
10
10
|
extend(RbSupport::RbDsl)
|
11
11
|
@step_mother = StepMother.new
|
12
12
|
@step_mother.load_natural_language('en')
|
13
|
-
@step_mother.load_programming_language('rb')
|
13
|
+
@rb = @step_mother.load_programming_language('rb')
|
14
14
|
|
15
15
|
$x = $y = nil
|
16
16
|
Before do
|
@@ -19,12 +19,19 @@ module Cucumber
|
|
19
19
|
Given /y is (\d+)/ do |n|
|
20
20
|
$y = $x * n.to_i
|
21
21
|
end
|
22
|
+
|
23
|
+
register
|
24
|
+
|
22
25
|
@visitor = Visitor.new(@step_mother)
|
23
26
|
@visitor.options = {}
|
24
27
|
|
25
28
|
@feature = mock('feature', :visit? => true).as_null_object
|
26
29
|
end
|
27
30
|
|
31
|
+
def register
|
32
|
+
@step_mother.register_step_definitions(@rb.step_definitions)
|
33
|
+
end
|
34
|
+
|
28
35
|
it "should execute Before blocks before background steps" do
|
29
36
|
background = Background.new(
|
30
37
|
comment=Comment.new(''),
|
@@ -285,6 +285,16 @@ module Cucumber
|
|
285
285
|
| aslak | true |
|
286
286
|
}
|
287
287
|
end
|
288
|
+
|
289
|
+
it "should not allow mappings that match more than 1 column" do
|
290
|
+
t1 = Table.new([
|
291
|
+
['Cuke', 'Duke'],
|
292
|
+
['Foo', 'Bar']
|
293
|
+
])
|
294
|
+
lambda do
|
295
|
+
t1.map_headers!(/uk/ => 'u')
|
296
|
+
end.should raise_error(%{2 headers matched /uk/: ["Cuke", "Duke"]})
|
297
|
+
end
|
288
298
|
|
289
299
|
describe "raising" do
|
290
300
|
before do
|
@@ -46,7 +46,7 @@ module Cli
|
|
46
46
|
|
47
47
|
context '-r or --require' do
|
48
48
|
it "collects all specified files into an array" do
|
49
|
-
after_parsing
|
49
|
+
after_parsing('--require some_file.rb -r another_file.rb') do
|
50
50
|
options[:require].should == ['some_file.rb', 'another_file.rb']
|
51
51
|
end
|
52
52
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
require 'cucumber/ast'
|
4
|
+
require 'cucumber/step_mother'
|
5
|
+
require 'cucumber/rb_support/rb_language'
|
6
|
+
|
7
|
+
module Cucumber
|
8
|
+
module RbSupport
|
9
|
+
describe RbStepDefinition do
|
10
|
+
before do
|
11
|
+
@step_mother = StepMother.new
|
12
|
+
@step_mother.load_natural_language('en')
|
13
|
+
@rb = @step_mother.load_programming_language('rb')
|
14
|
+
@dsl = Object.new
|
15
|
+
@dsl.extend RbSupport::RbDsl
|
16
|
+
@step_mother.before(nil)
|
17
|
+
|
18
|
+
$inside = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def register
|
22
|
+
@step_mother.register_step_definitions(@rb.step_definitions)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should allow calling of other steps" do
|
26
|
+
@dsl.Given /Outside/ do
|
27
|
+
Given "Inside"
|
28
|
+
end
|
29
|
+
@dsl.Given /Inside/ do
|
30
|
+
$inside = true
|
31
|
+
end
|
32
|
+
register
|
33
|
+
|
34
|
+
@step_mother.step_match("Outside").invoke(nil)
|
35
|
+
$inside.should == true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow calling of other steps with inline arg" do
|
39
|
+
@dsl.Given /Outside/ do
|
40
|
+
Given "Inside", Ast::Table.new([['inside']])
|
41
|
+
end
|
42
|
+
@dsl.Given /Inside/ do |table|
|
43
|
+
$inside = table.raw[0][0]
|
44
|
+
end
|
45
|
+
register
|
46
|
+
|
47
|
+
@step_mother.step_match("Outside").invoke(nil)
|
48
|
+
$inside.should == 'inside'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise Undefined when inside step is not defined" do
|
52
|
+
@dsl.Given /Outside/ do
|
53
|
+
Given 'Inside'
|
54
|
+
end
|
55
|
+
register
|
56
|
+
|
57
|
+
lambda do
|
58
|
+
@step_mother.step_match('Outside').invoke(nil)
|
59
|
+
end.should raise_error(Undefined, 'Undefined step: "Inside"')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow forced pending" do
|
63
|
+
@dsl.Given /Outside/ do
|
64
|
+
pending("Do me!")
|
65
|
+
end
|
66
|
+
register
|
67
|
+
|
68
|
+
lambda do
|
69
|
+
@step_mother.step_match("Outside").invoke(nil)
|
70
|
+
end.should raise_error(Pending, "Do me!")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should allow announce" do
|
74
|
+
v = mock('visitor')
|
75
|
+
v.should_receive(:announce).with('wasup')
|
76
|
+
@step_mother.visitor = v
|
77
|
+
@dsl.Given /Loud/ do
|
78
|
+
announce 'wasup'
|
79
|
+
end
|
80
|
+
register
|
81
|
+
|
82
|
+
@step_mother.step_match("Loud").invoke(nil)
|
83
|
+
end
|
84
|
+
|
85
|
+
def unindented(s)
|
86
|
+
s.split("\n")[1..-2].join("\n").indent(-10)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should recognise quotes in name and make according regexp" do
|
90
|
+
@rb.snippet_text('Given', 'A "first" arg').should == unindented(%{
|
91
|
+
Given /^A "([^\\"]*)" arg$/ do |arg1|
|
92
|
+
pending
|
93
|
+
end
|
94
|
+
})
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should recognise several quoted words in name and make according regexp and args" do
|
98
|
+
@rb.snippet_text('Given', 'A "first" and "second" arg').should == unindented(%{
|
99
|
+
Given /^A "([^\\"]*)" and "([^\\"]*)" arg$/ do |arg1, arg2|
|
100
|
+
pending
|
101
|
+
end
|
102
|
+
})
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not use quote group when there are no quotes" do
|
106
|
+
@rb.snippet_text('Given', 'A first arg').should == unindented(%{
|
107
|
+
Given /^A first arg$/ do
|
108
|
+
pending
|
109
|
+
end
|
110
|
+
})
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -16,11 +16,17 @@ module Cucumber
|
|
16
16
|
@visitor = mock('Visitor')
|
17
17
|
end
|
18
18
|
|
19
|
+
def register
|
20
|
+
@step_mother.register_step_definitions(@rb.step_definitions)
|
21
|
+
end
|
22
|
+
|
19
23
|
it "should format step names" do
|
20
24
|
@dsl.Given(/it (.*) in (.*)/) do |what, month|
|
21
25
|
end
|
22
26
|
@dsl.Given(/nope something else/) do |what, month|
|
23
27
|
end
|
28
|
+
register
|
29
|
+
|
24
30
|
format = @step_mother.step_match("it snows in april").format_args("[%s]")
|
25
31
|
format.should == "it [snows] in [april]"
|
26
32
|
end
|
@@ -28,13 +34,14 @@ module Cucumber
|
|
28
34
|
it "should raise Ambiguous error with guess hint when multiple step definitions match" do
|
29
35
|
@dsl.Given(/Three (.*) mice/) {|disability|}
|
30
36
|
@dsl.Given(/Three blind (.*)/) {|animal|}
|
37
|
+
register
|
31
38
|
|
32
39
|
lambda do
|
33
40
|
@step_mother.step_match("Three blind mice")
|
34
41
|
end.should raise_error(Ambiguous, %{Ambiguous match of "Three blind mice":
|
35
42
|
|
36
|
-
spec/cucumber/step_mother_spec.rb:
|
37
|
-
spec/cucumber/step_mother_spec.rb:
|
43
|
+
spec/cucumber/step_mother_spec.rb:35:in `/Three (.*) mice/'
|
44
|
+
spec/cucumber/step_mother_spec.rb:36:in `/Three blind (.*)/'
|
38
45
|
|
39
46
|
You can run again with --guess to make Cucumber be more smart about it
|
40
47
|
})
|
@@ -42,15 +49,17 @@ You can run again with --guess to make Cucumber be more smart about it
|
|
42
49
|
|
43
50
|
it "should not show --guess hint when --guess is used" do
|
44
51
|
@step_mother.options = {:guess => true}
|
52
|
+
|
45
53
|
@dsl.Given(/Three (.*) mice/) {|disability|}
|
46
54
|
@dsl.Given(/Three cute (.*)/) {|animal|}
|
55
|
+
register
|
47
56
|
|
48
57
|
lambda do
|
49
58
|
@step_mother.step_match("Three cute mice")
|
50
59
|
end.should raise_error(Ambiguous, %{Ambiguous match of "Three cute mice":
|
51
60
|
|
52
|
-
spec/cucumber/step_mother_spec.rb:
|
53
|
-
spec/cucumber/step_mother_spec.rb:
|
61
|
+
spec/cucumber/step_mother_spec.rb:53:in `/Three (.*) mice/'
|
62
|
+
spec/cucumber/step_mother_spec.rb:54:in `/Three cute (.*)/'
|
54
63
|
|
55
64
|
})
|
56
65
|
end
|
@@ -59,6 +68,7 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
59
68
|
@step_mother.options = {:guess => true}
|
60
69
|
@dsl.Given(/Three (.*) mice/) {|disability|}
|
61
70
|
@dsl.Given(/Three (.*)/) {|animal|}
|
71
|
+
register
|
62
72
|
|
63
73
|
lambda do
|
64
74
|
@step_mother.step_match("Three blind mice")
|
@@ -69,6 +79,8 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
69
79
|
@step_mother.options = {:guess => true}
|
70
80
|
right = @dsl.Given(/Three (.*) mice/) {|disability|}
|
71
81
|
wrong = @dsl.Given(/Three (.*)/) {|animal|}
|
82
|
+
register
|
83
|
+
|
72
84
|
@step_mother.step_match("Three blind mice").step_definition.should == right
|
73
85
|
end
|
74
86
|
|
@@ -76,6 +88,8 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
76
88
|
@step_mother.options = {:guess => true}
|
77
89
|
right = @dsl.Given(/Three (.*) mice ran (.*)/) {|disability|}
|
78
90
|
wrong = @dsl.Given(/Three (.*)/) {|animal|}
|
91
|
+
register
|
92
|
+
|
79
93
|
@step_mother.step_match("Three blind mice ran far").step_definition.should == right
|
80
94
|
end
|
81
95
|
|
@@ -84,6 +98,8 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
84
98
|
general = @dsl.Given(/Three (.*) mice ran (.*)/) {|disability|}
|
85
99
|
specific = @dsl.Given(/Three blind mice ran far/) {}
|
86
100
|
more_specific = @dsl.Given(/^Three blind mice ran far$/) {}
|
101
|
+
register
|
102
|
+
|
87
103
|
@step_mother.step_match("Three blind mice ran far").step_definition.should == more_specific
|
88
104
|
end
|
89
105
|
|
@@ -97,6 +113,7 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
97
113
|
@dsl.Given(/Three (.*) mice/) {|disability|}
|
98
114
|
lambda do
|
99
115
|
@dsl.Given(/Three (.*) mice/) {|disability|}
|
116
|
+
register
|
100
117
|
end.should raise_error(Redundant)
|
101
118
|
end
|
102
119
|
|
@@ -104,6 +121,7 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
104
121
|
it "should not raise Redundant unless it's really redundant" do
|
105
122
|
@dsl.Given(/^(.*) (.*) user named '(.*)'$/) {|a,b,c|}
|
106
123
|
@dsl.Given(/^there is no (.*) user named '(.*)'$/) {|a,b|}
|
124
|
+
register
|
107
125
|
end
|
108
126
|
|
109
127
|
it "should raise an error if the world is nil" do
|
@@ -115,7 +133,7 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
115
133
|
raise "Should fail"
|
116
134
|
rescue RbSupport::NilWorld => e
|
117
135
|
e.message.should == "World procs should never return nil"
|
118
|
-
e.backtrace.should == ["spec/cucumber/step_mother_spec.rb:
|
136
|
+
e.backtrace.should == ["spec/cucumber/step_mother_spec.rb:128:in `World'"]
|
119
137
|
end
|
120
138
|
end
|
121
139
|
|
@@ -130,7 +148,7 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
130
148
|
|
131
149
|
it "should implicitly extend world with modules" do
|
132
150
|
@dsl.World(ModuleOne, ModuleTwo)
|
133
|
-
@step_mother.
|
151
|
+
@step_mother.before(nil)
|
134
152
|
class << @rb.current_world
|
135
153
|
included_modules.index(ModuleOne).should_not == nil
|
136
154
|
included_modules.index(ModuleTwo).should_not == nil
|
@@ -145,10 +163,10 @@ spec/cucumber/step_mother_spec.rb:46:in `/Three cute (.*)/'
|
|
145
163
|
end.should raise_error(RbSupport::MultipleWorld, %{You can only pass a proc to #World once, but it's happening
|
146
164
|
in 2 places:
|
147
165
|
|
148
|
-
spec/cucumber/step_mother_spec.rb:
|
149
|
-
spec/cucumber/step_mother_spec.rb:
|
166
|
+
spec/cucumber/step_mother_spec.rb:160:in `World'
|
167
|
+
spec/cucumber/step_mother_spec.rb:162:in `World'
|
150
168
|
|
151
|
-
Use Ruby modules instead to extend your worlds. See the Cucumber::
|
169
|
+
Use Ruby modules instead to extend your worlds. See the Cucumber::RbSupport::RbDsl#World RDoc
|
152
170
|
or http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world.
|
153
171
|
|
154
172
|
})
|
@@ -157,12 +175,13 @@ or http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world.
|
|
157
175
|
it "should find before hooks" do
|
158
176
|
fish = @dsl.Before('@fish'){}
|
159
177
|
meat = @dsl.Before('@meat'){}
|
178
|
+
register
|
160
179
|
|
161
180
|
scenario = mock('Scenario')
|
162
181
|
scenario.should_receive(:accept_hook?).with(fish).and_return(true)
|
163
182
|
scenario.should_receive(:accept_hook?).with(meat).and_return(false)
|
164
183
|
|
165
|
-
@
|
184
|
+
@rb.hooks_for(:before, scenario).should == [fish]
|
166
185
|
end
|
167
186
|
end
|
168
187
|
end
|