aslakhellesoy-cucumber 0.3.95 → 0.3.96

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +9 -3
  3. data/examples/sinatra/features/support/env.rb +1 -3
  4. data/features/cucumber_cli.feature +1 -0
  5. data/features/drb_server_integration.feature +56 -3
  6. data/features/junit_formatter.feature +23 -12
  7. data/features/step_definitions/cucumber_steps.rb +13 -2
  8. data/features/support/env.rb +19 -3
  9. data/lib/cucumber/ast/feature_element.rb +1 -1
  10. data/lib/cucumber/ast/step.rb +1 -1
  11. data/lib/cucumber/ast/step_invocation.rb +3 -2
  12. data/lib/cucumber/cli/configuration.rb +9 -25
  13. data/lib/cucumber/cli/drb_client.rb +7 -3
  14. data/lib/cucumber/cli/language_help_formatter.rb +4 -4
  15. data/lib/cucumber/cli/main.rb +26 -46
  16. data/lib/cucumber/cli/options.rb +3 -0
  17. data/lib/cucumber/constantize.rb +28 -0
  18. data/lib/cucumber/feature_file.rb +3 -3
  19. data/lib/cucumber/formatter/junit.rb +13 -9
  20. data/lib/cucumber/formatter/pretty.rb +2 -2
  21. data/lib/cucumber/language_support/hook_methods.rb +9 -0
  22. data/lib/cucumber/language_support/language_methods.rb +47 -0
  23. data/lib/cucumber/language_support/step_definition_methods.rb +44 -0
  24. data/lib/cucumber/parser/natural_language.rb +72 -0
  25. data/lib/cucumber/rb_support/rb_dsl.rb +73 -0
  26. data/lib/cucumber/rb_support/rb_hook.rb +19 -0
  27. data/lib/cucumber/rb_support/rb_language.rb +129 -0
  28. data/lib/cucumber/rb_support/rb_step_definition.rb +56 -0
  29. data/lib/cucumber/step_match.rb +2 -2
  30. data/lib/cucumber/step_mother.rb +87 -206
  31. data/lib/cucumber/version.rb +1 -1
  32. data/lib/cucumber/webrat/element_locator.rb +7 -7
  33. data/lib/cucumber/world.rb +28 -8
  34. data/rails_generators/cucumber/templates/cucumber_environment.rb +2 -2
  35. data/rails_generators/cucumber/templates/spork_env.rb +0 -2
  36. data/rails_generators/cucumber/templates/webrat_steps.rb +17 -0
  37. data/spec/cucumber/ast/background_spec.rb +8 -5
  38. data/spec/cucumber/ast/feature_factory.rb +4 -5
  39. data/spec/cucumber/ast/feature_spec.rb +7 -1
  40. data/spec/cucumber/ast/scenario_outline_spec.rb +10 -6
  41. data/spec/cucumber/ast/scenario_spec.rb +8 -3
  42. data/spec/cucumber/ast/step_collection_spec.rb +2 -2
  43. data/spec/cucumber/cli/configuration_spec.rb +15 -0
  44. data/spec/cucumber/cli/drb_client_spec.rb +35 -1
  45. data/spec/cucumber/cli/main_spec.rb +5 -4
  46. data/spec/cucumber/cli/options_spec.rb +6 -0
  47. data/spec/cucumber/parser/feature_parser_spec.rb +6 -5
  48. data/spec/cucumber/parser/table_parser_spec.rb +1 -1
  49. data/spec/cucumber/step_definition_spec.rb +26 -25
  50. data/spec/cucumber/step_mother_spec.rb +46 -41
  51. data/spec/cucumber/world/pending_spec.rb +4 -5
  52. metadata +11 -5
  53. data/lib/cucumber/cli/rb_step_def_loader.rb +0 -14
  54. data/lib/cucumber/parser/i18n/language.rb +0 -87
  55. data/lib/cucumber/step_definition.rb +0 -122
@@ -1,6 +1,10 @@
1
- require 'cucumber/step_definition'
1
+ require 'cucumber/constantize'
2
2
  require 'cucumber/world'
3
3
  require 'cucumber/core_ext/instance_exec'
4
+ require 'cucumber/parser/natural_language'
5
+ require 'cucumber/language_support/hook_methods'
6
+ require 'cucumber/language_support/language_methods'
7
+ require 'cucumber/language_support/step_definition_methods'
4
8
 
5
9
  module Cucumber
6
10
  class Undefined < StandardError
@@ -45,61 +49,56 @@ module Cucumber
45
49
  end
46
50
  end
47
51
 
48
- class NilWorld < StandardError
49
- def initialize
50
- super("World procs should never return nil")
51
- end
52
- end
53
-
54
- class MultipleWorld < StandardError
55
- def initialize(first_proc, second_proc)
56
- message = "You can only pass a proc to #World once, but it's happening\n"
57
- message << "in 2 places:\n\n"
58
- message << first_proc.backtrace_line('World') << "\n"
59
- message << second_proc.backtrace_line('World') << "\n\n"
60
- message << "Use Ruby modules instead to extend your worlds. See the Cucumber::StepMother#World RDoc\n"
61
- message << "or http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world.\n\n"
62
- super(message)
63
- end
64
- end
65
-
66
52
  # This is the main interface for registering step definitions, which is done
67
53
  # from <tt>*_steps.rb</tt> files. This module is included right at the top-level
68
54
  # so #register_step_definition (and more interestingly - its aliases) are
69
55
  # available from the top-level.
70
- module StepMother
71
- class Hook
72
- def initialize(tag_names, proc)
73
- @tag_names = tag_names.map{|tag| Ast::Tags.strip_prefix(tag)}
74
- @proc = proc
75
- end
56
+ class StepMother
57
+ include Constantize
58
+
59
+ attr_writer :options, :visitor
76
60
 
77
- def matches_tag_names?(tag_names)
78
- @tag_names.empty? || (@tag_names & tag_names).any?
79
- end
61
+ def initialize
62
+ @programming_languages = []
63
+ @language_map = {}
64
+ load_natural_language('en')
65
+ end
80
66
 
81
- def execute_in(world, scenario, location, exception_fails_scenario = true)
82
- begin
83
- world.cucumber_instance_exec(false, location, scenario, &@proc)
84
- rescue Exception => exception
85
- if exception_fails_scenario
86
- scenario.fail!(exception)
87
- else
88
- raise
89
- end
90
- end
91
- end
67
+ # Loads and registers programming language implementation.
68
+ # Instances are cached, so calling with the same argument
69
+ # twice will return the same instance.
70
+ #
71
+ # Raises an exception if the language can't be loaded.
72
+ #
73
+ def load_programming_language(ext)
74
+ return @language_map[ext] if @language_map[ext]
75
+ programming_language_class = constantize("Cucumber::#{ext.capitalize}Support::#{ext.capitalize}Language")
76
+ programming_language = programming_language_class.new(self)
77
+ programming_language.alias_adverbs(@adverbs || [])
78
+ @programming_languages << programming_language
79
+ @language_map[ext] = programming_language
80
+ programming_language
81
+ end
82
+
83
+ # Loads a natural language. This has the effect of aliasing
84
+ # Step Definition keywords for all of the registered programming
85
+ # languages (if they support aliasing). See #load_programming_language
86
+ #
87
+ def load_natural_language(lang)
88
+ Parser::NaturalLanguage.get(self, lang)
92
89
  end
93
90
 
94
- class << self
95
- def alias_adverb(adverb)
96
- adverb = adverb.gsub(/\s/, '')
97
- alias_method adverb, :register_step_definition
91
+ # Registers a StepDefinition. This can be a Ruby StepDefintion,
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)
98
97
  end
98
+ step_definitions << step_definition
99
+ step_definition
99
100
  end
100
101
 
101
- attr_writer :snippet_generator, :options, :visitor
102
-
103
102
  def options
104
103
  @options ||= {}
105
104
  end
@@ -117,6 +116,10 @@ module Cucumber
117
116
  end
118
117
  end
119
118
 
119
+ def announce(msg)
120
+ @visitor.announce(msg)
121
+ end
122
+
120
123
  def scenarios(status = nil)
121
124
  @scenarios ||= []
122
125
  if(status)
@@ -126,44 +129,8 @@ module Cucumber
126
129
  end
127
130
  end
128
131
 
129
- # Registers a new StepDefinition. This method is aliased
130
- # to <tt>Given</tt>, <tt>When</tt> and <tt>Then</tt>, and
131
- # also to the i18n translations whenever a feature of a
132
- # new language is loaded.
133
- #
134
- # See Cucumber#alias_steps for details on how to
135
- # create your own aliases.
136
- #
137
- # The +&proc+ gets executed in the context of a <tt>world</tt>
138
- # object, which is defined by #World. A new <tt>world</tt>
139
- # object is created for each scenario and is shared across
140
- # step definitions within that scenario.
141
- def register_step_definition(regexp, &proc)
142
- step_definition = StepDefinition.new(regexp, &proc)
143
- step_definitions.each do |already|
144
- raise Redundant.new(already, step_definition) if already.match(regexp)
145
- end
146
- step_definitions << step_definition
147
- step_definition
148
- end
149
-
150
- # Registers a Before proc. You can call this method as many times as you
151
- # want (typically from ruby scripts under <tt>support</tt>).
152
- def Before(*tag_names, &proc)
153
- register_hook(:before, tag_names, proc)
154
- end
155
-
156
- def After(*tag_names, &proc)
157
- register_hook(:after, tag_names, proc)
158
- end
159
-
160
- def AfterStep(*tag_names, &proc)
161
- register_hook(:after_step, tag_names, proc)
162
- end
163
-
164
- def register_hook(phase, tags, proc)
165
- hook = Hook.new(tags, proc)
166
- hooks[phase] << hook
132
+ def register_hook(phase, hook)
133
+ hooks[phase.to_sym] << hook
167
134
  hook
168
135
  end
169
136
 
@@ -172,53 +139,7 @@ module Cucumber
172
139
  end
173
140
 
174
141
  def hooks_for(phase, scenario)
175
- hooks[phase].select{|hook| scenario.accept_hook?(hook)}
176
- end
177
-
178
- # Registers any number of +world_modules+ (Ruby Modules) and/or a Proc.
179
- # The +proc+ will be executed once before each scenario to create an
180
- # Object that the scenario's steps will run within. Any +world_modules+
181
- # will be mixed into this Object (via Object#extend).
182
- #
183
- # This method is typically called from one or more Ruby scripts under
184
- # <tt>features/support</tt>. You can call this method as many times as you
185
- # like (to register more modules), but if you try to register more than
186
- # one Proc you will get an error.
187
- #
188
- # Cucumber will not yield anything to the +proc+ (like it used to do before v0.3).
189
- #
190
- # In earlier versions of Cucumber (before 0.3) you could not register
191
- # any +world_modules+. Instead you would register several Proc objects (by
192
- # calling the method several times). The result of each +proc+ would be yielded
193
- # to the next +proc+. Example:
194
- #
195
- # World do |world| # NOT SUPPORTED FROM 0.3
196
- # MyClass.new
197
- # end
198
- #
199
- # World do |world| # NOT SUPPORTED FROM 0.3
200
- # world.extend(MyModule)
201
- # end
202
- #
203
- # From Cucumber 0.3 the recommended way to do this is:
204
- #
205
- # World do
206
- # MyClass.new
207
- # end
208
- #
209
- # World(MyModule)
210
- #
211
- def World(*world_modules, &proc)
212
- if(proc)
213
- raise MultipleWorld.new(@world_proc, proc) if @world_proc
214
- @world_proc = proc
215
- end
216
- @world_modules ||= []
217
- @world_modules += world_modules
218
- end
219
-
220
- def current_world
221
- @current_world
142
+ hooks[phase.to_sym].select{|hook| scenario.accept_hook?(hook)}
222
143
  end
223
144
 
224
145
  def step_match(step_name, formatted_step_name=nil)
@@ -257,108 +178,68 @@ module Cucumber
257
178
  end
258
179
 
259
180
  def snippet_text(step_keyword, step_name, multiline_arg_class)
260
- @snippet_generator.snippet_text(step_keyword, step_name, multiline_arg_class)
181
+ @programming_languages.map do |programming_language|
182
+ programming_language.snippet_text(step_keyword, step_name, multiline_arg_class)
183
+ end.join("\n")
261
184
  end
262
185
 
263
186
  def before_and_after(scenario, skip_hooks=false)
264
187
  before(scenario) unless skip_hooks
265
- @current_scenario = scenario
266
188
  yield scenario
267
- @current_scenario = nil
268
189
  after(scenario) unless skip_hooks
269
190
  scenario_visited(scenario)
270
191
  end
271
-
272
- def before(scenario)
273
- unless current_world
274
- new_world!
275
- execute_before(scenario)
276
- end
277
- end
278
-
279
- def after(scenario)
280
- execute_after(scenario)
281
- nil_world!
282
- end
283
-
284
- def after_step
285
- execute_after_step(@current_scenario)
286
- end
287
-
288
- private
289
192
 
290
- def max_step_definition_length
291
- @max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
193
+ def register_adverbs(adverbs)
194
+ @adverbs ||= []
195
+ @adverbs += adverbs
196
+ @adverbs.uniq!
197
+ @programming_languages.each do |programming_language|
198
+ programming_language.alias_adverbs(@adverbs)
199
+ end
292
200
  end
293
201
 
294
- # Creates a new world instance
295
- def new_world!
202
+ def begin_scenario
296
203
  return if options[:dry_run]
297
- create_world!
298
- extend_world
299
- connect_world
300
- @current_world
301
- end
302
-
303
- def create_world!
304
- if(@world_proc)
305
- @current_world = @world_proc.call
306
- check_nil(@current_world, @world_proc)
307
- else
308
- @current_world = Object.new
204
+ @programming_languages.each do |programming_language|
205
+ programming_language.begin_scenario
309
206
  end
310
207
  end
311
208
 
312
- def extend_world
313
- @current_world.extend(World)
314
- @current_world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
315
- (@world_modules || []).each do |mod|
316
- @current_world.extend(mod)
209
+ def end_scenario
210
+ return if options[:dry_run]
211
+ @programming_languages.each do |programming_language|
212
+ programming_language.end_scenario
317
213
  end
318
214
  end
319
-
320
- def connect_world
321
- @current_world.__cucumber_step_mother = self
322
- @current_world.__cucumber_visitor = @visitor
323
- end
324
-
325
- def check_nil(o, proc)
326
- if o.nil?
327
- begin
328
- raise NilWorld.new
329
- rescue NilWorld => e
330
- e.backtrace.clear
331
- e.backtrace.push(proc.backtrace_line("World"))
332
- raise e
333
- end
334
- else
335
- o
215
+
216
+ def before(scenario)
217
+ return if options[:dry_run] || @current_scenario
218
+ @current_scenario = scenario
219
+ @programming_languages.each do |programming_language|
220
+ programming_language.before(scenario)
336
221
  end
337
222
  end
338
-
339
- def nil_world!
340
- @current_world = nil
341
- end
342
-
343
- def execute_before(scenario)
223
+
224
+ def after(scenario)
225
+ @current_scenario = nil
344
226
  return if options[:dry_run]
345
- hooks_for(:before, scenario).each do |hook|
346
- hook.execute_in(@current_world, scenario, 'Before')
227
+ @programming_languages.each do |programming_language|
228
+ programming_language.after(scenario)
347
229
  end
348
230
  end
349
-
350
- def execute_after(scenario)
231
+
232
+ def after_step
351
233
  return if options[:dry_run]
352
- hooks_for(:after, scenario).each do |hook|
353
- hook.execute_in(@current_world, scenario, 'After')
234
+ @programming_languages.each do |programming_language|
235
+ programming_language.execute_after_step(@current_scenario)
354
236
  end
355
237
  end
238
+
239
+ private
356
240
 
357
- def execute_after_step(scenario)
358
- return if options[:dry_run]
359
- hooks_for(:after_step, scenario).each do |hook|
360
- hook.execute_in(@current_world, scenario, 'AfterStep', false)
361
- end
241
+ def max_step_definition_length
242
+ @max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
362
243
  end
363
244
 
364
245
  def scenario_visited(scenario)
@@ -2,7 +2,7 @@ module Cucumber #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 95
5
+ TINY = 96
6
6
  PATCH = nil # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
@@ -1,15 +1,15 @@
1
1
  module Webrat
2
2
  class Element
3
- # Returns an Array of Array of String where each String is the
4
- # a "cell" in the table-like structure represented by this Element.
3
+ # Returns an Array of Array of String where each String is a
4
+ # "cell" in the table-like structure represented by this Element.
5
5
  #
6
- # Supported elements are table, dl, ol and ul. The return value depends
7
- # on the type of the element:
6
+ # Supported elements are table, dl, ol and ul. Different conversion
7
+ # strategies are used depending on the kind of element:
8
8
  #
9
- # * table : Each tr is a row. The innerHTML of each tr or th becomes cells. The number
9
+ # * table : Each tr becomes a row. The innerHTML of each td or th inside becomes a cell. The number
10
10
  # of columns is determined by the number of cells in the first row.
11
- # * dl : Each dt creates a row with 2 cells. The innerHTML of the dt itself and the next dd become cells.
12
- # * ul or ol : Each ul creates a row with one cell, the innerHTML of the ul.
11
+ # * dl : Each dt becomes a row with 2 cells. The innerHTML of the dt itself and the next dd become cells.
12
+ # * ul or ol : Each li becomes a row with one cell, the innerHTML of the li.
13
13
  #
14
14
  def to_table
15
15
  case element.name
@@ -7,23 +7,43 @@ module Cucumber
7
7
  end
8
8
  end
9
9
 
10
- attr_writer :__cucumber_step_mother, :__cucumber_visitor, :__cucumber_current_step
10
+ attr_writer :__cucumber_step_mother
11
11
 
12
12
  # Call a step from within a step definition
13
13
  def __cucumber_invoke(name, multiline_argument=nil) #:nodoc:
14
14
  begin
15
15
  step_match = @__cucumber_step_mother.step_match(name)
16
- step_match.invoke(self, multiline_argument)
16
+ step_match.invoke(multiline_argument)
17
17
  rescue Exception => e
18
18
  e.nested! if Undefined === e
19
- @__cucumber_current_step.exception = e if @__cucumber_current_step
20
19
  raise e
21
20
  end
22
21
  end
23
-
24
- def table(text, file=nil, line_offset=0)
25
- @table_parser ||= Parser::TableParser.new
26
- @table_parser.parse_or_fail(text.strip, file, line_offset)
22
+
23
+ # Returns a Cucumber::Ast::Table for +text_or_table+, which can either
24
+ # be a String:
25
+ #
26
+ # table(%{
27
+ # | account | description | amount |
28
+ # | INT-100 | Taxi | 114 |
29
+ # | CUC-101 | Peeler | 22 |
30
+ # })
31
+ #
32
+ # or a 2D Array:
33
+ #
34
+ # table([
35
+ # %w{ account description amount },
36
+ # %w{ INT-100 Taxi 114 },
37
+ # %w{ CUC-101 Peeler 22 }
38
+ # ])
39
+ #
40
+ def table(text_or_table, file=nil, line_offset=0)
41
+ if Array === text_or_table
42
+ Ast::Table.new(text_or_table)
43
+ else
44
+ @table_parser ||= Parser::TableParser.new
45
+ @table_parser.parse_or_fail(text_or_table.strip, file, line_offset)
46
+ end
27
47
  end
28
48
 
29
49
  # Output +announcement+ alongside the formatted output.
@@ -34,7 +54,7 @@ module Cucumber
34
54
  # step. This is because the step itself will not be printed until
35
55
  # after it has run, so it can be coloured according to its status.
36
56
  def announce(announcement)
37
- @__cucumber_visitor.announce(announcement)
57
+ @__cucumber_step_mother.announce(announcement)
38
58
  end
39
59
 
40
60
  def pending(message = "TODO")
@@ -16,11 +16,11 @@ config.action_controller.allow_forgery_protection = false
16
16
  config.action_mailer.delivery_method = :test
17
17
 
18
18
  config.gem 'cucumber', :lib => false, :version => '>=<%= cucumber_version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
- config.gem 'webrat', :lib => false, :version => '>=0.4.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
19
+ config.gem 'webrat', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
20
20
  <% if framework == :rspec -%>
21
21
  config.gem 'rspec', :lib => false, :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
22
22
  config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
23
23
  <% end %>
24
24
  <% if spork? -%>
25
- config.gem 'spork', :lib => false, :version => '>=0.5.7' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
25
+ config.gem 'spork', :lib => false, :version => '>=0.5.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
26
26
  <% end %>
@@ -18,14 +18,12 @@ Spork.prefork do
18
18
 
19
19
  # Comment out the next line if you don't want Cucumber Unicode support
20
20
  require 'cucumber/formatter/unicode'
21
-
22
21
  require 'spec/rails'
23
22
  require 'cucumber/rails/rspec'
24
23
  end
25
24
 
26
25
  Spork.each_run do
27
26
  # This code will be run each time you run your specs.
28
- require 'cucumber/rails/world'
29
27
 
30
28
  # Comment out the next line if you don't want transactions to
31
29
  # open/roll back around each scenario
@@ -27,6 +27,23 @@ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
27
27
  fill_in(field, :with => value)
28
28
  end
29
29
 
30
+ # Use this to fill in an entire form with data from a table. Example:
31
+ #
32
+ # When I fill in the following:
33
+ # | Account Number | 5002 |
34
+ # | Expiry date | 2009-11-01 |
35
+ # | Note | Nice guy |
36
+ # | Wants Email? | |
37
+ #
38
+ # TODO: Add support for checkbox, select og option
39
+ # based on naming conventions.
40
+ #
41
+ When /^I fill in the following:$/ do |fields|
42
+ fields.rows_hash.each do |name, value|
43
+ When %{I fill in "#{name}" with "#{value}"}
44
+ end
45
+ end
46
+
30
47
  When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
31
48
  select(value, :from => field)
32
49
  end
@@ -1,18 +1,22 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
  require 'cucumber/ast'
3
+ require 'cucumber/rb_support/rb_language'
3
4
 
4
5
  module Cucumber
5
6
  module Ast
6
7
  describe Background do
7
8
 
8
9
  before do
9
- @step_mother = Object.new
10
- @step_mother.extend(StepMother)
10
+ extend(RbSupport::RbDsl)
11
+ @step_mother = StepMother.new
12
+ @step_mother.load_natural_language('en')
13
+ @step_mother.load_programming_language('rb')
14
+
11
15
  $x = $y = nil
12
- @step_mother.Before do
16
+ Before do
13
17
  $x = 2
14
18
  end
15
- @step_mother.Given /y is (\d+)/ do |n|
19
+ Given /y is (\d+)/ do |n|
16
20
  $y = $x * n.to_i
17
21
  end
18
22
  @visitor = Visitor.new(@step_mother)
@@ -40,7 +44,6 @@ module Cucumber
40
44
  name="",
41
45
  steps=[])
42
46
  background.feature = @feature
43
-
44
47
  @visitor.visit_background(background)
45
48
  $x.should == 2
46
49
  $y.should == 10
@@ -10,14 +10,13 @@ module Cucumber
10
10
  end
11
11
  end
12
12
 
13
- def create_feature(step_mother)
14
- step_mother.extend(StepMother)
15
- step_mother.Given /^a (.*) step with an inline arg:$/ do |what, table|
13
+ def create_feature(dsl)
14
+ dsl.Given /^a (.*) step with an inline arg:$/ do |what, table|
16
15
  end
17
- step_mother.Given /^a (.*) step$/ do |what|
16
+ dsl.Given /^a (.*) step$/ do |what|
18
17
  flunk if what == 'failing'
19
18
  end
20
- step_mother.World do
19
+ dsl.World do
21
20
  MyWorld.new
22
21
  end
23
22
 
@@ -7,7 +7,13 @@ module Cucumber
7
7
  include FeatureFactory
8
8
 
9
9
  it "should convert to sexp" do
10
- feature = create_feature(Object.new)
10
+ step_mother = StepMother.new
11
+ step_mother.load_natural_language('en')
12
+ step_mother.load_programming_language('rb')
13
+ dsl = Object.new
14
+ dsl.extend RbSupport::RbDsl
15
+
16
+ feature = create_feature(dsl)
11
17
  feature.to_sexp.should ==
12
18
  [:feature,
13
19
  "features/pretty_printing.feature",
@@ -2,24 +2,28 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
  require 'cucumber/step_mother'
3
3
  require 'cucumber/ast'
4
4
  require 'cucumber/core_ext/string'
5
+ require 'cucumber/rb_support/rb_language'
5
6
 
6
7
  module Cucumber
7
8
  module Ast
8
9
  describe ScenarioOutline do
9
10
  before do
10
- @step_mother = Object.new
11
- @step_mother.extend(StepMother)
11
+ @step_mother = StepMother.new
12
+ @step_mother.load_programming_language('rb')
13
+ @step_mother.load_natural_language('en')
14
+ @dsl = Object.new
15
+ @dsl.extend(RbSupport::RbDsl)
12
16
 
13
- @step_mother.Given(/^there are (\d+) cucumbers$/) do |n|
17
+ @dsl.Given(/^there are (\d+) cucumbers$/) do |n|
14
18
  @initial = n.to_i
15
19
  end
16
- @step_mother.When(/^I eat (\d+) cucumbers$/) do |n|
20
+ @dsl.When(/^I eat (\d+) cucumbers$/) do |n|
17
21
  @eaten = n.to_i
18
22
  end
19
- @step_mother.Then(/^I should have (\d+) cucumbers$/) do |n|
23
+ @dsl.Then(/^I should have (\d+) cucumbers$/) do |n|
20
24
  (@initial - @eaten).should == n.to_i
21
25
  end
22
- @step_mother.Then(/^I should have (\d+) cucumbers in my belly$/) do |n|
26
+ @dsl.Then(/^I should have (\d+) cucumbers in my belly$/) do |n|
23
27
  @eaten.should == n.to_i
24
28
  end
25
29
 
@@ -1,15 +1,20 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
  require 'cucumber/step_mother'
3
3
  require 'cucumber/ast'
4
+ require 'cucumber/rb_support/rb_language'
4
5
 
5
6
  module Cucumber
6
7
  module Ast
7
8
  describe Scenario do
8
9
  before do
9
- @step_mother = Object.new
10
- @step_mother.extend(StepMother)
10
+ @step_mother = StepMother.new
11
+ @step_mother.load_natural_language('en')
12
+ @step_mother.load_programming_language('rb')
13
+ @dsl = Object.new
14
+ @dsl.extend(RbSupport::RbDsl)
15
+
11
16
  $x = $y = nil
12
- @step_mother.Given /y is (\d+)/ do |n|
17
+ @dsl.Given /y is (\d+)/ do |n|
13
18
  $y = n.to_i
14
19
  end
15
20
  @visitor = Visitor.new(@step_mother)
@@ -6,8 +6,8 @@ module Cucumber
6
6
  it "should convert And to Given in snippets" do
7
7
  s1 = Step.new(1, 'Given', 'cukes')
8
8
  s2 = Step.new(2, 'And', 'turnips')
9
- s1.stub!(:language).and_return(Parser::I18n::Language['en'])
10
- s2.stub!(:language).and_return(Parser::I18n::Language['en'])
9
+ s1.stub!(:language).and_return(Parser::NaturalLanguage.get(nil, 'en'))
10
+ s2.stub!(:language).and_return(Parser::NaturalLanguage.get(nil, 'en'))
11
11
  c = StepCollection.new([s1, s2])
12
12
  actual_keywords = c.step_invocations.map{|i| i.actual_keyword}
13
13
  actual_keywords.should == %w{Given Given}