cucumber 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/.rspec +1 -1
  2. data/Caliper.yml +4 -0
  3. data/History.txt +1557 -0
  4. data/LICENSE +1 -1
  5. data/README.rdoc +26 -0
  6. data/Rakefile +51 -5
  7. data/VERSION.yml +5 -0
  8. data/bin/cucumber +1 -7
  9. data/cucumber.gemspec +77 -3
  10. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -1
  11. data/examples/i18n/he/features/step_definitons/calculator_steps.rb +1 -1
  12. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +7 -4
  13. data/examples/i18n/ro/features/suma.feature +11 -0
  14. data/examples/i18n/ru/features/division.feature +2 -2
  15. data/examples/i18n/tr/features/step_definitons/hesap_makinesi_adimlari.rb +3 -3
  16. data/examples/sinatra/features/support/env.rb +5 -2
  17. data/examples/v8/features/fibonacci.feature +1 -1
  18. data/examples/watir/features/step_definitions/search_steps.rb +1 -1
  19. data/features/announce.feature +164 -0
  20. data/features/around_hooks.feature +232 -0
  21. data/features/background.feature +95 -284
  22. data/features/bug_371.feature +32 -0
  23. data/features/bug_464.feature +16 -0
  24. data/features/bug_475.feature +42 -0
  25. data/features/bug_585_tab_indentation.feature +22 -0
  26. data/features/bug_600.feature +67 -0
  27. data/features/call_steps_from_stepdefs.feature +154 -0
  28. data/features/cucumber_cli.feature +591 -0
  29. data/features/cucumber_cli_outlines.feature +117 -0
  30. data/features/custom_formatter.feature +73 -3
  31. data/features/default_snippets.feature +42 -0
  32. data/features/diffing.feature +25 -0
  33. data/features/drb_server_integration.feature +174 -0
  34. data/features/exception_in_after_block.feature +127 -0
  35. data/features/exception_in_after_step_block.feature +104 -0
  36. data/features/exception_in_before_block.feature +98 -0
  37. data/features/exclude_files.feature +20 -0
  38. data/features/expand.feature +60 -0
  39. data/features/html_formatter.feature +8 -0
  40. data/features/html_formatter/a.html +582 -0
  41. data/features/json_formatter.feature +245 -160
  42. data/features/junit_formatter.feature +88 -0
  43. data/features/language_from_header.feature +30 -0
  44. data/features/language_help.feature +78 -0
  45. data/features/listener_debugger_formatter.feature +42 -0
  46. data/features/multiline_names.feature +44 -0
  47. data/features/negative_tagged_hooks.feature +60 -0
  48. data/features/post_configuration_hook.feature +37 -0
  49. data/features/profiles.feature +126 -0
  50. data/features/rake_task.feature +152 -0
  51. data/features/report_called_undefined_steps.feature +34 -0
  52. data/features/rerun_formatter.feature +45 -0
  53. data/features/simplest.feature +11 -0
  54. data/features/snippet.feature +23 -0
  55. data/features/snippets_when_using_star_keyword.feature +36 -0
  56. data/features/step_definitions/cucumber_steps.rb +153 -7
  57. data/features/step_definitions/extra_steps.rb +2 -0
  58. data/features/step_definitions/simplest_steps.rb +3 -0
  59. data/features/step_definitions/wire_steps.rb +32 -0
  60. data/features/support/env.rb +140 -18
  61. data/features/support/env.rb.simplest +7 -0
  62. data/features/support/fake_wire_server.rb +77 -0
  63. data/features/table_diffing.feature +45 -0
  64. data/features/table_mapping.feature +34 -0
  65. data/features/tag_logic.feature +258 -0
  66. data/features/transform.feature +245 -0
  67. data/features/unicode_table.feature +35 -0
  68. data/features/usage_and_stepdefs_formatter.feature +169 -0
  69. data/features/wire_protocol.feature +332 -0
  70. data/features/wire_protocol_table_diffing.feature +119 -0
  71. data/features/wire_protocol_tags.feature +87 -0
  72. data/features/wire_protocol_timeouts.feature +63 -0
  73. data/features/work_in_progress.feature +156 -0
  74. data/fixtures/json/features/pystring.feature +8 -0
  75. data/fixtures/junit/features/pending.feature +1 -3
  76. data/fixtures/self_test/features/background/background_tagged_before_on_outline.feature +12 -0
  77. data/fixtures/self_test/features/background/background_with_name.feature +7 -0
  78. data/fixtures/self_test/features/background/failing_background.feature +12 -0
  79. data/fixtures/self_test/features/background/failing_background_after_success.feature +11 -0
  80. data/fixtures/self_test/features/background/multiline_args_background.feature +32 -0
  81. data/fixtures/self_test/features/background/passing_background.feature +10 -0
  82. data/fixtures/self_test/features/background/pending_background.feature +10 -0
  83. data/fixtures/self_test/features/background/scenario_outline_failing_background.feature +16 -0
  84. data/fixtures/self_test/features/background/scenario_outline_passing_background.feature +16 -0
  85. data/fixtures/self_test/features/support/env.rb +0 -8
  86. data/fixtures/tickets/features.html +1 -1
  87. data/gem_tasks/examples.rake +1 -1
  88. data/gem_tasks/features.rake +14 -0
  89. data/gem_tasks/sdoc.rake +12 -0
  90. data/lib/cucumber.rb +0 -12
  91. data/lib/cucumber/ast.rb +1 -1
  92. data/lib/cucumber/ast/background.rb +5 -21
  93. data/lib/cucumber/ast/examples.rb +4 -12
  94. data/lib/cucumber/ast/feature.rb +5 -13
  95. data/lib/cucumber/ast/feature_element.rb +4 -9
  96. data/lib/cucumber/ast/outline_table.rb +4 -4
  97. data/lib/cucumber/ast/py_string.rb +80 -0
  98. data/lib/cucumber/ast/scenario.rb +5 -7
  99. data/lib/cucumber/ast/scenario_outline.rb +15 -23
  100. data/lib/cucumber/ast/step.rb +0 -5
  101. data/lib/cucumber/ast/step_invocation.rb +15 -21
  102. data/lib/cucumber/ast/table.rb +8 -14
  103. data/lib/cucumber/ast/tree_walker.rb +48 -10
  104. data/lib/cucumber/cli/configuration.rb +8 -33
  105. data/lib/cucumber/cli/main.rb +35 -20
  106. data/lib/cucumber/cli/options.rb +7 -8
  107. data/lib/cucumber/cli/profile_loader.rb +0 -2
  108. data/lib/cucumber/core_ext/proc.rb +1 -2
  109. data/lib/cucumber/feature_file.rb +15 -47
  110. data/lib/cucumber/formatter/ansicolor.rb +5 -3
  111. data/lib/cucumber/formatter/color_io.rb +23 -0
  112. data/lib/cucumber/formatter/console.rb +23 -27
  113. data/lib/cucumber/formatter/cucumber.css +17 -34
  114. data/lib/cucumber/formatter/cucumber.sass +182 -173
  115. data/lib/cucumber/formatter/html.rb +11 -46
  116. data/lib/cucumber/formatter/io.rb +4 -2
  117. data/lib/cucumber/formatter/json.rb +152 -15
  118. data/lib/cucumber/formatter/json_pretty.rb +6 -5
  119. data/lib/cucumber/formatter/junit.rb +22 -28
  120. data/lib/cucumber/formatter/pdf.rb +6 -6
  121. data/lib/cucumber/formatter/pretty.rb +5 -5
  122. data/lib/cucumber/formatter/rerun.rb +11 -22
  123. data/lib/cucumber/formatter/tag_cloud.rb +35 -0
  124. data/lib/cucumber/formatter/unicode.rb +20 -41
  125. data/lib/cucumber/js_support/js_dsl.js +4 -4
  126. data/lib/cucumber/js_support/js_language.rb +5 -9
  127. data/lib/cucumber/js_support/js_snippets.rb +2 -2
  128. data/lib/cucumber/language_support.rb +2 -2
  129. data/lib/cucumber/parser/gherkin_builder.rb +30 -35
  130. data/lib/cucumber/platform.rb +8 -8
  131. data/lib/cucumber/py_support/py_language.rb +2 -2
  132. data/lib/cucumber/rake/task.rb +31 -74
  133. data/lib/cucumber/rb_support/rb_dsl.rb +0 -1
  134. data/lib/cucumber/rb_support/rb_language.rb +8 -10
  135. data/lib/cucumber/rb_support/rb_step_definition.rb +0 -8
  136. data/lib/cucumber/rb_support/rb_transform.rb +0 -17
  137. data/lib/cucumber/rb_support/rb_world.rb +18 -26
  138. data/lib/cucumber/rspec/doubles.rb +3 -3
  139. data/lib/cucumber/step_match.rb +2 -6
  140. data/lib/cucumber/step_mother.rb +427 -6
  141. data/lib/cucumber/wire_support/configuration.rb +1 -4
  142. data/lib/cucumber/wire_support/wire_language.rb +10 -3
  143. data/spec/cucumber/ast/background_spec.rb +6 -68
  144. data/spec/cucumber/ast/feature_factory.rb +4 -5
  145. data/spec/cucumber/ast/feature_spec.rb +4 -4
  146. data/spec/cucumber/ast/outline_table_spec.rb +1 -1
  147. data/spec/cucumber/ast/py_string_spec.rb +40 -0
  148. data/spec/cucumber/ast/scenario_outline_spec.rb +11 -15
  149. data/spec/cucumber/ast/scenario_spec.rb +4 -4
  150. data/spec/cucumber/ast/step_spec.rb +3 -3
  151. data/spec/cucumber/ast/table_spec.rb +2 -38
  152. data/spec/cucumber/ast/tree_walker_spec.rb +2 -2
  153. data/spec/cucumber/broadcaster_spec.rb +1 -1
  154. data/spec/cucumber/cli/configuration_spec.rb +6 -32
  155. data/spec/cucumber/cli/drb_client_spec.rb +3 -2
  156. data/spec/cucumber/cli/main_spec.rb +43 -43
  157. data/spec/cucumber/cli/options_spec.rb +1 -28
  158. data/spec/cucumber/cli/profile_loader_spec.rb +1 -1
  159. data/spec/cucumber/core_ext/proc_spec.rb +1 -1
  160. data/spec/cucumber/formatter/ansicolor_spec.rb +1 -1
  161. data/spec/cucumber/formatter/color_io_spec.rb +29 -0
  162. data/spec/cucumber/formatter/duration_spec.rb +1 -1
  163. data/spec/cucumber/formatter/html_spec.rb +5 -3
  164. data/spec/cucumber/formatter/junit_spec.rb +2 -16
  165. data/spec/cucumber/formatter/progress_spec.rb +1 -1
  166. data/spec/cucumber/formatter/spec_helper.rb +12 -11
  167. data/spec/cucumber/rb_support/rb_language_spec.rb +28 -241
  168. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +28 -33
  169. data/spec/cucumber/rb_support/regexp_argument_matcher_spec.rb +1 -1
  170. data/spec/cucumber/step_match_spec.rb +9 -11
  171. data/spec/cucumber/step_mother_spec.rb +302 -0
  172. data/spec/cucumber/wire_support/configuration_spec.rb +1 -1
  173. data/spec/cucumber/wire_support/connection_spec.rb +1 -1
  174. data/spec/cucumber/wire_support/wire_exception_spec.rb +1 -1
  175. data/spec/cucumber/wire_support/wire_language_spec.rb +1 -1
  176. data/spec/cucumber/wire_support/wire_packet_spec.rb +1 -1
  177. data/spec/cucumber/wire_support/wire_step_definition_spec.rb +1 -1
  178. data/spec/cucumber/world/pending_spec.rb +2 -2
  179. data/spec/spec_helper.rb +20 -13
  180. metadata +78 -4
@@ -1,282 +1,69 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
2
3
  require 'cucumber/step_mother'
3
4
  require 'cucumber/rb_support/rb_language'
4
5
 
5
6
  module Cucumber
6
7
  module RbSupport
7
8
  describe RbStepDefinition do
8
- let(:user_interface) { double('user interface') }
9
- let(:rb) { support_code.load_programming_language('rb')}
10
- let(:support_code) do
11
- Cucumber::Runtime::SupportCode.new(user_interface, {})
12
- end
13
- let(:dsl) do
14
- rb
15
- Object.new.extend(RbSupport::RbDsl)
9
+ before do
10
+ @step_mother = Cucumber::StepMother.new
11
+ @rb = @step_mother.load_programming_language('rb')
16
12
  end
17
13
 
18
14
  def unindented(s)
19
15
  s.split("\n")[1..-2].join("\n").indent(-10)
20
16
  end
21
-
22
- describe "snippets" do
23
17
 
24
- it "should recognise numbers in name and make according regexp" do
25
- rb.snippet_text('Given', 'Cloud 9 yeah', nil).should == unindented(%{
18
+ it "should recognise numbers in name and make according regexp" do
19
+ @rb.snippet_text('Given', 'Cloud 9 yeah', nil).should == unindented(%{
26
20
  Given /^Cloud (\\d+) yeah$/ do |arg1|
27
21
  pending # express the regexp above with the code you wish you had
28
22
  end
29
- })
30
- end
23
+ })
24
+ end
31
25
 
32
- it "should recognise a mix of ints, strings and why not a table too" do
33
- rb.snippet_text('Given', 'I have 9 "awesome" cukes in 37 "boxes"', Cucumber::Ast::Table).should == unindented(%{
26
+ it "should recognise a mix of ints, strings and why not a table too" do
27
+ @rb.snippet_text('Given', 'I have 9 "awesome" cukes in 37 "boxes"', Cucumber::Ast::Table).should == unindented(%{
34
28
  Given /^I have (\\d+) "([^"]*)" cukes in (\\d+) "([^"]*)"$/ do |arg1, arg2, arg3, arg4, table|
35
29
  # table is a Cucumber::Ast::Table
36
30
  pending # express the regexp above with the code you wish you had
37
31
  end
38
- })
39
- end
32
+ })
33
+ end
40
34
 
41
- it "should recognise quotes in name and make according regexp" do
42
- rb.snippet_text('Given', 'A "first" arg', nil).should == unindented(%{
35
+ it "should recognise quotes in name and make according regexp" do
36
+ @rb.snippet_text('Given', 'A "first" arg', nil).should == unindented(%{
43
37
  Given /^A "([^"]*)" arg$/ do |arg1|
44
38
  pending # express the regexp above with the code you wish you had
45
39
  end
46
- })
47
- end
40
+ })
41
+ end
48
42
 
49
- it "should recognise several quoted words in name and make according regexp and args" do
50
- rb.snippet_text('Given', 'A "first" and "second" arg', nil).should == unindented(%{
43
+ it "should recognise several quoted words in name and make according regexp and args" do
44
+ @rb.snippet_text('Given', 'A "first" and "second" arg', nil).should == unindented(%{
51
45
  Given /^A "([^"]*)" and "([^"]*)" arg$/ do |arg1, arg2|
52
46
  pending # express the regexp above with the code you wish you had
53
47
  end
54
- })
55
- end
48
+ })
49
+ end
56
50
 
57
- it "should not use quote group when there are no quotes" do
58
- rb.snippet_text('Given', 'A first arg', nil).should == unindented(%{
51
+ it "should not use quote group when there are no quotes" do
52
+ @rb.snippet_text('Given', 'A first arg', nil).should == unindented(%{
59
53
  Given /^A first arg$/ do
60
54
  pending # express the regexp above with the code you wish you had
61
55
  end
62
- })
63
- end
56
+ })
57
+ end
64
58
 
65
- it "should be helpful with tables" do
66
- rb.snippet_text('Given', 'A "first" arg', Cucumber::Ast::Table).should == unindented(%{
59
+ it "should be helpful with tables" do
60
+ @rb.snippet_text('Given', 'A "first" arg', Cucumber::Ast::Table).should == unindented(%{
67
61
  Given /^A "([^"]*)" arg$/ do |arg1, table|
68
62
  # table is a Cucumber::Ast::Table
69
63
  pending # express the regexp above with the code you wish you had
70
64
  end
71
- })
72
- end
73
-
74
- end
75
-
76
- describe "#load_code_file" do
77
- after do
78
- FileUtils.rm_rf('tmp.rb')
79
- end
80
-
81
- def a_file_called(name)
82
- File.open('tmp.rb', 'w') do |f|
83
- f.puts yield
84
- end
85
- end
86
-
87
- it "re-loads the file when called multiple times" do
88
- a_file_called('tmp.rb') do
89
- "$foo = 1"
90
- end
91
-
92
- rb.load_code_file('tmp.rb')
93
- $foo.should == 1
94
-
95
- a_file_called('tmp.rb') do
96
- "$foo = 2"
97
- end
98
-
99
- rb.load_code_file('tmp.rb')
100
- $foo.should == 2
101
- end
102
- end
103
-
104
- describe "Handling the World" do
105
-
106
- it "should raise an error if the world is nil" do
107
- dsl.World {}
108
-
109
- begin
110
- rb.before(nil)
111
- raise "Should fail"
112
- rescue RbSupport::NilWorld => e
113
- e.message.should == "World procs should never return nil"
114
- e.backtrace.length.should == 1
115
- e.backtrace[0].should =~ /spec\/cucumber\/rb_support\/rb_language_spec\.rb\:\d+\:in `World'/
116
- end
117
- end
118
-
119
- module ModuleOne
120
- end
121
-
122
- module ModuleTwo
123
- end
124
-
125
- class ClassOne
126
- end
127
-
128
- it "should implicitly extend world with modules" do
129
- dsl.World(ModuleOne, ModuleTwo)
130
- rb.before(mock('scenario').as_null_object)
131
- class << rb.current_world
132
- included_modules.inspect.should =~ /ModuleOne/ # Workaround for RSpec/Ruby 1.9 issue with namespaces
133
- included_modules.inspect.should =~ /ModuleTwo/
134
- end
135
- rb.current_world.class.should == Object
136
- end
137
-
138
- it "should raise error when we try to register more than one World proc" do
139
- expected_error = %{You can only pass a proc to #World once, but it's happening
140
- in 2 places:
141
-
142
- spec/cucumber/rb_support/rb_language_spec.rb:\\d+:in `World'
143
- spec/cucumber/rb_support/rb_language_spec.rb:\\d+:in `World'
144
-
145
- Use Ruby modules instead to extend your worlds. See the Cucumber::RbSupport::RbDsl#World RDoc
146
- or http://wiki.github.com/cucumber/cucumber/a-whole-new-world.
147
-
148
- }
149
- dsl.World { Hash.new }
150
- lambda do
151
- dsl.World { Array.new }
152
- end.should raise_error(RbSupport::MultipleWorld, /#{expected_error}/)
153
-
154
- end
155
- end
156
-
157
- describe "step argument transformations" do
158
-
159
- describe "without capture groups" do
160
- it "complains when registering with a with no transform block" do
161
- lambda do
162
- dsl.Transform('^abc$')
163
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
164
- end
165
-
166
- it "complains when registering with a zero-arg transform block" do
167
- lambda do
168
- dsl.Transform('^abc$') {42}
169
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
170
- end
171
-
172
- it "complains when registering with a splat-arg transform block" do
173
- lambda do
174
- dsl.Transform('^abc$') {|*splat| 42 }
175
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
176
- end
177
-
178
- it "complains when transforming with an arity mismatch" do
179
- lambda do
180
- dsl.Transform('^abc$') {|one, two| 42 }
181
- rb.execute_transforms(['abc'])
182
- end.should raise_error(Cucumber::ArityMismatchError)
183
- end
184
-
185
- it "allows registering a regexp pattern that yields the step_arg matched" do
186
- dsl.Transform(/^ab*c$/) {|arg| 42}
187
- rb.execute_transforms(['ab']).should == ['ab']
188
- rb.execute_transforms(['ac']).should == [42]
189
- rb.execute_transforms(['abc']).should == [42]
190
- rb.execute_transforms(['abbc']).should == [42]
191
- end
192
- end
193
-
194
- describe "with capture groups" do
195
- it "complains when registering with a with no transform block" do
196
- lambda do
197
- dsl.Transform('^a(.)c$')
198
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
199
- end
200
-
201
- it "complains when registering with a zero-arg transform block" do
202
- lambda do
203
- dsl.Transform('^a(.)c$') { 42 }
204
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
205
- end
206
-
207
- it "complains when registering with a splat-arg transform block" do
208
- lambda do
209
- dsl.Transform('^a(.)c$') {|*splat| 42 }
210
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
211
- end
212
-
213
- it "complains when transforming with an arity mismatch" do
214
- lambda do
215
- dsl.Transform('^a(.)c$') {|one, two| 42 }
216
- rb.execute_transforms(['abc'])
217
- end.should raise_error(Cucumber::ArityMismatchError)
218
- end
219
-
220
- it "allows registering a regexp pattern that yields capture groups" do
221
- dsl.Transform(/^shape: (.+), color: (.+)$/) do |shape, color|
222
- {shape.to_sym => color.to_sym}
223
- end
224
- rb.execute_transforms(['shape: circle, color: blue']).should == [{:circle => :blue}]
225
- rb.execute_transforms(['shape: square, color: red']).should == [{:square => :red}]
226
- rb.execute_transforms(['not shape: square, not color: red']).should == ['not shape: square, not color: red']
227
- end
228
- end
229
-
230
- it "allows registering a string pattern" do
231
- dsl.Transform('^ab*c$') {|arg| 42}
232
- rb.execute_transforms(['ab']).should == ['ab']
233
- rb.execute_transforms(['ac']).should == [42]
234
- rb.execute_transforms(['abc']).should == [42]
235
- rb.execute_transforms(['abbc']).should == [42]
236
- end
237
-
238
- it "gives match priority to transforms defined last" do
239
- dsl.Transform(/^transform_me$/) {|arg| :foo }
240
- dsl.Transform(/^transform_me$/) {|arg| :bar }
241
- dsl.Transform(/^transform_me$/) {|arg| :baz }
242
- rb.execute_transforms(['transform_me']).should == [:baz]
243
- end
244
-
245
- it "allows registering a transform which returns nil" do
246
- dsl.Transform('^ac$') {|arg| nil}
247
- rb.execute_transforms(['ab']).should == ['ab']
248
- rb.execute_transforms(['ac']).should == [nil]
249
- end
250
- end
251
-
252
- describe "hooks" do
253
-
254
- it "should find before hooks" do
255
- fish = dsl.Before('@fish'){}
256
- meat = dsl.Before('@meat'){}
257
-
258
- scenario = mock('Scenario')
259
- scenario.should_receive(:accept_hook?).with(fish).and_return(true)
260
- scenario.should_receive(:accept_hook?).with(meat).and_return(false)
261
-
262
- rb.hooks_for(:before, scenario).should == [fish]
263
- end
264
-
265
- it "should find around hooks" do
266
- a = dsl.Around do |scenario, block|
267
- end
268
-
269
- b = dsl.Around('@tag') do |scenario, block|
270
- end
271
-
272
- scenario = mock('Scenario')
273
- scenario.should_receive(:accept_hook?).with(a).and_return(true)
274
- scenario.should_receive(:accept_hook?).with(b).and_return(false)
275
-
276
- rb.hooks_for(:around, scenario).should == [a]
277
- end
65
+ })
278
66
  end
279
-
280
67
  end
281
68
  end
282
69
  end
@@ -1,4 +1,5 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
2
3
  require 'cucumber/ast'
3
4
  require 'cucumber/step_mother'
4
5
  require 'cucumber/rb_support/rb_language'
@@ -6,92 +7,86 @@ require 'cucumber/rb_support/rb_language'
6
7
  module Cucumber
7
8
  module RbSupport
8
9
  describe RbStepDefinition do
9
- let(:user_interface) { double('user interface') }
10
- let(:support_code) { Cucumber::Runtime::SupportCode.new(user_interface) }
11
- let(:rb) { support_code.load_programming_language('rb')}
12
- let(:dsl) do
13
- rb
14
- Object.new.extend(Cucumber::RbSupport::RbDsl)
15
- end
16
-
17
10
  before do
18
- rb.before(mock('scenario').as_null_object)
11
+ @step_mother = Cucumber::StepMother.new
12
+ @rb = @step_mother.load_programming_language('rb')
13
+ @dsl = Object.new
14
+ @dsl.extend Cucumber::RbSupport::RbDsl
15
+ @step_mother.before(mock('scenario').as_null_object)
19
16
 
20
17
  $inside = nil
21
18
  end
22
19
 
23
20
  it "should allow calling of other steps" do
24
- dsl.Given /Outside/ do
21
+ @dsl.Given /Outside/ do
25
22
  Given "Inside"
26
23
  end
27
- dsl.Given /Inside/ do
24
+ @dsl.Given /Inside/ do
28
25
  $inside = true
29
26
  end
30
27
 
31
- support_code.step_match("Outside").invoke(nil)
28
+ @step_mother.step_match("Outside").invoke(nil)
32
29
  $inside.should == true
33
30
  end
34
31
 
35
32
  it "should allow calling of other steps with inline arg" do
36
- dsl.Given /Outside/ do
33
+ @dsl.Given /Outside/ do
37
34
  Given "Inside", Cucumber::Ast::Table.new([['inside']])
38
35
  end
39
- dsl.Given /Inside/ do |table|
36
+ @dsl.Given /Inside/ do |table|
40
37
  $inside = table.raw[0][0]
41
38
  end
42
39
 
43
- support_code.step_match("Outside").invoke(nil)
40
+ @step_mother.step_match("Outside").invoke(nil)
44
41
  $inside.should == 'inside'
45
42
  end
46
43
 
47
44
  it "should raise Undefined when inside step is not defined" do
48
- dsl.Given /Outside/ do
45
+ @dsl.Given /Outside/ do
49
46
  Given 'Inside'
50
47
  end
51
48
 
52
49
  lambda do
53
- support_code.step_match('Outside').invoke(nil)
50
+ @step_mother.step_match('Outside').invoke(nil)
54
51
  end.should raise_error(Cucumber::Undefined, 'Undefined step: "Inside"')
55
52
  end
56
53
 
57
54
  it "should allow forced pending" do
58
- dsl.Given /Outside/ do
55
+ @dsl.Given /Outside/ do
59
56
  pending("Do me!")
60
57
  end
61
58
 
62
59
  lambda do
63
- support_code.step_match("Outside").invoke(nil)
60
+ @step_mother.step_match("Outside").invoke(nil)
64
61
  end.should raise_error(Cucumber::Pending, "Do me!")
65
62
  end
66
63
 
67
64
  it "should raise ArityMismatchError when the number of capture groups differs from the number of step arguments" do
68
- dsl.Given /No group: \w+/ do |arg|
65
+ @dsl.Given /No group: \w+/ do |arg|
69
66
  end
70
67
 
71
68
  lambda do
72
- support_code.step_match("No group: arg").invoke(nil)
69
+ @step_mother.step_match("No group: arg").invoke(nil)
73
70
  end.should raise_error(Cucumber::ArityMismatchError)
74
71
  end
75
72
 
76
- it "should allow puts" do
77
- user_interface.should_receive(:puts).with('wasup')
78
- dsl.Given /Loud/ do
79
- puts 'wasup'
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'
80
79
  end
81
80
 
82
- support_code.step_match("Loud").invoke(nil)
81
+ @step_mother.step_match("Loud").invoke(nil)
83
82
  end
84
83
 
85
84
  it "should recognize $arg style captures" do
86
- dsl.Given "capture this: $arg" do |arg|
85
+ @dsl.Given "capture this: $arg" do |arg|
87
86
  arg.should == 'this'
88
87
  end
89
88
 
90
- support_code.step_match('capture this: this').invoke(nil)
91
- end
92
-
93
- it "should have a JSON representation of the signature" do
94
- RbStepDefinition.new(rb, /I CAN HAZ (\d+) CUKES/i, lambda{}).to_hash.should == {'source' => "I CAN HAZ (\\d+) CUKES", 'flags' => 'i'}
89
+ @step_mother.step_match('capture this: this').invoke(nil)
95
90
  end
96
91
  end
97
92
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
  require 'cucumber/rb_support/regexp_argument_matcher'
3
3
 
4
4
  module Cucumber
@@ -1,12 +1,10 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  require 'cucumber/rb_support/rb_step_definition'
4
4
  require 'cucumber/rb_support/rb_language'
5
5
 
6
6
  module Cucumber
7
7
  describe StepMatch do
8
- WORD = Cucumber::RUBY_1_9 ? '[[:word:]]' : '\w'
9
-
10
8
  before do
11
9
  @rb_language = RbSupport::RbLanguage.new(nil)
12
10
  end
@@ -21,38 +19,38 @@ module Cucumber
21
19
  end
22
20
 
23
21
  it "should format one group when we use Unicode" do
24
- m = step_match(/I (#{WORD}+) ok/, "I æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ ok")
22
+ m = step_match(/I (\w+) ok/, "I æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ ok")
25
23
  m.format_args("<span>%s</span>").should == "I <span>æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ</span> ok"
26
24
  end
27
25
 
28
26
  it "should format several groups when we use Unicode" do
29
- m = step_match(/I (#{WORD}+) (#{WORD}+) (#{WORD}+) this (#{WORD}+)/, "I ate æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ egg this morning")
27
+ m = step_match(/I (\w+) (\w+) (\w+) this (\w+)/, "I ate æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ egg this morning")
30
28
  m.format_args("<span>%s</span>").should == "I <span>ate</span> <span>æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ</span> <span>egg</span> this <span>morning</span>"
31
29
  end
32
30
 
33
31
  it "should deal with Unicode both inside and outside arguments" do
34
- "Jæ vø ålsker døtte løndet".should =~ /Jæ (.+) ålsker (.+) løndet/
35
- m = step_match(/Jæ (#{WORD}+) ålsker (#{WORD}+) løndet/, "Jæ vø ålsker døtte løndet")
32
+ "Jæ vø ålsker døtte løndet".should =~ /Jæ (\w+) ålsker (\w+) løndet/
33
+ m = step_match(/Jæ (\w+) ålsker (\w+) løndet/, "Jæ vø ålsker døtte løndet")
36
34
  m.format_args("<span>%s</span>").should == "Jæ <span>vø</span> ålsker <span>døtte</span> løndet"
37
35
  end
38
36
 
39
37
  it "should format groups with format string" do
40
- m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning")
38
+ m = step_match(/I (\w+) (\d+) (\w+) this (\w+)/, "I ate 1 egg this morning")
41
39
  m.format_args("<span>%s</span>").should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
42
40
  end
43
41
 
44
42
  it "should format groups with format string when there are dupes" do
45
- m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I bob 1 bo this bobs")
43
+ m = step_match(/I (\w+) (\d+) (\w+) this (\w+)/, "I bob 1 bo this bobs")
46
44
  m.format_args("<span>%s</span>").should == "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
47
45
  end
48
46
 
49
47
  it "should format groups with block" do
50
- m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning")
48
+ m = step_match(/I (\w+) (\d+) (\w+) this (\w+)/, "I ate 1 egg this morning")
51
49
  m.format_args(&lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
52
50
  end
53
51
 
54
52
  it "should format groups with proc object" do
55
- m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning")
53
+ m = step_match(/I (\w+) (\d+) (\w+) this (\w+)/, "I ate 1 egg this morning")
56
54
  m.format_args(lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
57
55
  end
58
56