cucumber 0.2.3 → 0.3.0

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.
Files changed (128) hide show
  1. data/History.txt +56 -1
  2. data/Manifest.txt +70 -49
  3. data/config/hoe.rb +1 -1
  4. data/cucumber.yml +1 -1
  5. data/examples/i18n/bg/Rakefile +6 -0
  6. data/examples/i18n/bg/features/addition.feature +11 -0
  7. data/examples/i18n/bg/features/consecutive_calculations.feature +18 -0
  8. data/examples/i18n/bg/features/division.feature +16 -0
  9. data/examples/i18n/bg/features/step_definitons/calculator_steps.rb +24 -0
  10. data/examples/i18n/bg/features/support/env.rb +6 -0
  11. data/examples/i18n/bg/features/support/world.rb +8 -0
  12. data/examples/i18n/bg/lib/calculator.rb +24 -0
  13. data/examples/i18n/ru/features/support/world.rb +4 -3
  14. data/examples/i18n/sk/Rakefile +6 -0
  15. data/examples/i18n/sk/features/addition.feature +16 -0
  16. data/examples/i18n/sk/features/division.feature +9 -0
  17. data/examples/i18n/sk/features/step_definitons/calculator_steps.rb +24 -0
  18. data/examples/i18n/sk/lib/calculator.rb +14 -0
  19. data/examples/self_test/features/background/background_with_name.feature +7 -0
  20. data/examples/self_test/features/background/passing_background.feature +2 -2
  21. data/examples/self_test/features/step_definitions/sample_steps.rb +18 -2
  22. data/examples/self_test/features/undefined_multiline_args.feature +12 -0
  23. data/examples/sinatra/features/support/env.rb +2 -6
  24. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +1 -4
  25. data/examples/tickets/Rakefile +1 -1
  26. data/examples/tickets/features/229/tagged_hooks.feature +8 -0
  27. data/examples/tickets/features/229/tagged_hooks.rb +14 -0
  28. data/examples/tickets/features/270/back.feature +14 -0
  29. data/examples/tickets/features/270/back.steps.rb +14 -0
  30. data/examples/tickets/features/279/py_string_indent.feature +25 -0
  31. data/examples/tickets/features/279/py_string_indent.steps.rb +12 -0
  32. data/examples/tickets/features/279/wrong.feature_ +11 -0
  33. data/examples/tickets/features/step_definitons/tickets_steps.rb +0 -7
  34. data/features/background.feature +21 -3
  35. data/features/cucumber_cli.feature +18 -5
  36. data/features/cucumber_cli_outlines.feature +4 -1
  37. data/features/rake_task.feature +132 -0
  38. data/features/snippet.feature +23 -0
  39. data/features/step_definitions/cucumber_steps.rb +46 -15
  40. data/features/support/env.rb +61 -4
  41. data/features/usage.feature +5 -0
  42. data/gem_tasks/deployment.rake +1 -1
  43. data/lib/cucumber/ast/background.rb +14 -4
  44. data/lib/cucumber/ast/examples.rb +0 -12
  45. data/lib/cucumber/ast/feature.rb +2 -12
  46. data/lib/cucumber/ast/feature_element.rb +4 -8
  47. data/lib/cucumber/ast/features.rb +1 -1
  48. data/lib/cucumber/ast/outline_table.rb +20 -20
  49. data/lib/cucumber/ast/py_string.rb +6 -11
  50. data/lib/cucumber/ast/scenario.rb +1 -8
  51. data/lib/cucumber/ast/scenario_outline.rb +1 -11
  52. data/lib/cucumber/ast/step.rb +3 -9
  53. data/lib/cucumber/ast/step_collection.rb +0 -4
  54. data/lib/cucumber/ast/step_invocation.rb +5 -6
  55. data/lib/cucumber/ast/table.rb +5 -22
  56. data/lib/cucumber/ast/tags.rb +9 -9
  57. data/lib/cucumber/ast/visitor.rb +12 -25
  58. data/lib/cucumber/cli/configuration.rb +4 -4
  59. data/lib/cucumber/cli/main.rb +10 -3
  60. data/lib/cucumber/core_ext/instance_exec.rb +17 -4
  61. data/lib/cucumber/formatter/ansicolor.rb +1 -1
  62. data/lib/cucumber/formatter/console.rb +2 -1
  63. data/lib/cucumber/formatter/html.rb +21 -7
  64. data/lib/cucumber/formatter/pretty.rb +27 -20
  65. data/lib/cucumber/formatter/usage.rb +16 -0
  66. data/lib/cucumber/languages.yml +23 -5
  67. data/lib/cucumber/parser/feature.rb +231 -114
  68. data/lib/cucumber/parser/feature.tt +120 -25
  69. data/lib/cucumber/parser/table.rb +37 -25
  70. data/lib/cucumber/parser/table.tt +15 -3
  71. data/lib/cucumber/parser/treetop_ext.rb +48 -9
  72. data/lib/cucumber/rake/task.rb +29 -6
  73. data/lib/cucumber/step_definition.rb +4 -2
  74. data/lib/cucumber/step_mother.rb +143 -26
  75. data/lib/cucumber/version.rb +2 -2
  76. data/rails_generators/cucumber/templates/paths.rb +13 -4
  77. data/rails_generators/cucumber/templates/webrat_steps.rb +16 -0
  78. data/{specs → spec}/cucumber/ast/background_spec.rb +1 -0
  79. data/{specs → spec}/cucumber/ast/feature_factory.rb +1 -1
  80. data/{specs → spec}/cucumber/ast/feature_spec.rb +2 -2
  81. data/{specs → spec}/cucumber/ast/py_string_spec.rb +0 -0
  82. data/{specs → spec}/cucumber/ast/scenario_outline_spec.rb +0 -0
  83. data/{specs → spec}/cucumber/ast/scenario_spec.rb +0 -27
  84. data/{specs → spec}/cucumber/ast/step_collection_spec.rb +0 -0
  85. data/{specs → spec}/cucumber/ast/step_spec.rb +0 -0
  86. data/{specs → spec}/cucumber/ast/table_spec.rb +2 -2
  87. data/{specs → spec}/cucumber/broadcaster_spec.rb +0 -0
  88. data/{specs → spec}/cucumber/cli/configuration_spec.rb +0 -0
  89. data/{specs → spec}/cucumber/cli/main_spec.rb +5 -1
  90. data/spec/cucumber/core_ext/proc_spec.rb +54 -0
  91. data/{specs → spec}/cucumber/core_ext/string_spec.rb +0 -0
  92. data/{specs → spec}/cucumber/formatter/ansicolor_spec.rb +0 -0
  93. data/{specs → spec}/cucumber/formatter/color_io_spec.rb +0 -0
  94. data/{specs → spec}/cucumber/formatter/html/cucumber.css +0 -0
  95. data/{specs → spec}/cucumber/formatter/html/cucumber.js +0 -0
  96. data/{specs → spec}/cucumber/formatter/html/index.html +0 -0
  97. data/{specs → spec}/cucumber/formatter/html/jquery-1.3.min.js +0 -0
  98. data/{specs → spec}/cucumber/formatter/html/jquery.uitableedit.js +0 -0
  99. data/{specs → spec}/cucumber/formatters/profile_formatter_spec.rb +0 -0
  100. data/{specs → spec}/cucumber/parser/feature_parser_spec.rb +43 -41
  101. data/{specs → spec}/cucumber/parser/table_parser_spec.rb +0 -0
  102. data/{specs → spec}/cucumber/rails/stubs/mini_rails.rb +0 -0
  103. data/{specs → spec}/cucumber/rails/stubs/test_help.rb +0 -0
  104. data/{specs → spec}/cucumber/rails/world_spec.rb +0 -0
  105. data/{specs → spec}/cucumber/sell_cucumbers.feature +0 -0
  106. data/{specs → spec}/cucumber/step_definition_spec.rb +0 -0
  107. data/{specs → spec}/cucumber/step_mother_spec.rb +63 -4
  108. data/{specs → spec}/cucumber/treetop_parser/empty_feature.feature +0 -0
  109. data/{specs → spec}/cucumber/treetop_parser/empty_scenario.feature +0 -0
  110. data/{specs → spec}/cucumber/treetop_parser/empty_scenario_outline.feature +0 -0
  111. data/{specs → spec}/cucumber/treetop_parser/fit_scenario.feature +0 -0
  112. data/{specs → spec}/cucumber/treetop_parser/given_scenario.feature +0 -0
  113. data/{specs → spec}/cucumber/treetop_parser/invalid_scenario_outlines.feature +0 -0
  114. data/{specs → spec}/cucumber/treetop_parser/multiline_steps.feature +0 -0
  115. data/{specs → spec}/cucumber/treetop_parser/multiple_tables.feature +0 -0
  116. data/{specs → spec}/cucumber/treetop_parser/scenario_outline.feature +0 -0
  117. data/{specs → spec}/cucumber/treetop_parser/spaces.feature +0 -0
  118. data/{specs → spec}/cucumber/treetop_parser/test_dos.feature +0 -0
  119. data/{specs → spec}/cucumber/treetop_parser/with_comments.feature +0 -0
  120. data/{specs → spec}/cucumber/treetop_parser/with_tags.feature +0 -0
  121. data/{specs → spec}/cucumber/world/pending_spec.rb +0 -0
  122. data/{specs → spec}/spec.opts +0 -0
  123. data/{specs → spec}/spec_helper.rb +2 -11
  124. metadata +72 -51
  125. data/examples/tickets/cucumber.yml +0 -3
  126. data/lib/cucumber/parser/basic.rb +0 -0
  127. data/specs/cucumber/ast/tags_spec.rb +0 -19
  128. data/specs/cucumber/core_ext/proc_spec.rb +0 -37
@@ -1,4 +1,16 @@
1
1
  module NavigationHelpers
2
+ # Maps a static name to a static route.
3
+ #
4
+ # This method is *not* designed to map from a dynamic name to a
5
+ # dynamic route like <tt>post_comments_path(post)</tt>. For dynamic
6
+ # routes like this you should *not* rely on #path_to, but write
7
+ # your own step definitions instead. Example:
8
+ #
9
+ # Given /I am on the comments page for the "(.+)" post/ |name|
10
+ # post = Post.find_by_name(name)
11
+ # visit post_comments_path(post)
12
+ # end
13
+ #
2
14
  def path_to(page_name)
3
15
  case page_name
4
16
 
@@ -14,7 +26,4 @@ module NavigationHelpers
14
26
  end
15
27
  end
16
28
 
17
- World do |world|
18
- world.extend NavigationHelpers
19
- world
20
- end
29
+ World(NavigationHelpers)
@@ -106,6 +106,22 @@ Then /^I should not see "([^\"]*)"$/ do |text|
106
106
  <% end -%>
107
107
  end
108
108
 
109
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
110
+ <% if framework == :rspec -%>
111
+ field_labeled(field).value.should =~ /#{value}/
112
+ <% else -%>
113
+ assert_match(/#{value}/, field_labeled(field).value)
114
+ <% end -%>
115
+ end
116
+
117
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
118
+ <% if framework == :rspec -%>
119
+ field_labeled(field).value.should_not =~ /#{value}/
120
+ <% else -%>
121
+ assert_no_match(/#{value}/, field_labeled(field).value)
122
+ <% end -%>
123
+ end
124
+
109
125
  Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
110
126
  <% if framework == :rspec -%>
111
127
  field_labeled(label).should be_checked
@@ -26,6 +26,7 @@ module Cucumber
26
26
  comment=Comment.new(''),
27
27
  line=2,
28
28
  keyword="",
29
+ name="",
29
30
  steps=[
30
31
  Step.new(7, "Given", "y is 5")
31
32
  ])
@@ -30,7 +30,7 @@ module Cucumber
30
30
  Cucumber sandwich
31
31
  }, 10)
32
32
 
33
- background = Ast::Background.new(Ast::Comment.new(""), 2, "Background:",
33
+ background = Ast::Background.new(Ast::Comment.new(""), 2, "Background:", "",
34
34
  [
35
35
  Step.new(3, "Given", "a passing step")
36
36
  ]
@@ -25,9 +25,9 @@ module Cucumber
25
25
  [:step_invocation, 3, "Given", "a passing step"], # From the background
26
26
  [:step_invocation, 10, "Given", "a passing step with an inline arg:",
27
27
  [:table,
28
- [:row,
28
+ [:row, -1,
29
29
  [:cell, "1"], [:cell, "22"], [:cell, "333"]],
30
- [:row,
30
+ [:row, -1,
31
31
  [:cell, "4444"], [:cell, "55555"], [:cell, "666666"]]]],
32
32
  [:step_invocation, 11, "Given", "a happy step with an inline arg:",
33
33
  [:py_string, "\n I like\nCucumber sandwich\n"]],
@@ -33,33 +33,6 @@ module Cucumber
33
33
  $y.should == nil
34
34
  end
35
35
 
36
- it "should be at exact line" do
37
- s = Scenario.new(background=nil, comment=Comment.new(""),
38
- tags=Tags.new(44, []), 45, keyword="", name="", steps=[])
39
-
40
- s.should be_matches_lines([44])
41
- s.should be_matches_lines([45])
42
- end
43
-
44
- it "should be at line if tags or steps are" do
45
- s = Scenario.new(
46
- background=nil,
47
- comment=Comment.new(""),
48
- tags=Tags.new(43, []),
49
- line=45,
50
- keyword="",
51
- name="",
52
- steps=[
53
- Step.new(46, "Given", ""),
54
- Step.new(47, "Given", ""),
55
- Step.new(48, "Given", ""),
56
- ]
57
- )
58
-
59
- s.should be_matches_lines([43])
60
- s.should be_matches_lines([47])
61
- s.should_not be_matches_lines([49])
62
- end
63
36
  end
64
37
  end
65
38
  end
@@ -155,12 +155,12 @@ module Cucumber
155
155
  it "should convert to sexp" do
156
156
  @table.to_sexp.should ==
157
157
  [:table,
158
- [:row,
158
+ [:row, -1,
159
159
  [:cell, "one"],
160
160
  [:cell, "four"],
161
161
  [:cell, "seven"]
162
162
  ],
163
- [:row,
163
+ [:row, -1,
164
164
  [:cell, "4444"],
165
165
  [:cell, "55555"],
166
166
  [:cell, "666666"]]]
@@ -1,6 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
  require 'yaml'
3
- require 'spec/expectations/differs/default'
3
+ begin
4
+ require 'spec/runner/differs/default' # RSpec >=1.2.4
5
+ rescue ::LoadError
6
+ require 'spec/expectations/differs/default' # RSpec <=1.2.3
7
+ end
4
8
 
5
9
  module Cucumber
6
10
  module Cli
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/core_ext/instance_exec'
3
+
4
+ describe Proc do
5
+ it "should remove extraneous path info for file" do
6
+ proc = lambda {|a,b|}
7
+ proc.file_colon_line.should =~ /^spec\/cucumber\/core_ext\/proc_spec\.rb:6/
8
+ end
9
+
10
+ it "should raise ArityMismatchError for too many args (expecting 0)" do
11
+ lambda {
12
+ Object.new.cucumber_instance_exec(true, 'foo', 1) do
13
+ end
14
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 0 arguments, but the Regexp matched 1 argument.")
15
+ end
16
+
17
+ it "should raise ArityMismatchError for too many args (expecting 1)" do
18
+ lambda {
19
+ Object.new.cucumber_instance_exec(true, 'foo', 1,2) do |a|
20
+ end
21
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 1 argument, but the Regexp matched 2 arguments.")
22
+ end
23
+
24
+ it "should raise ArityMismatchError for too few args (expecting 1)" do
25
+ lambda {
26
+ Object.new.cucumber_instance_exec(true, 'foo') do |a|
27
+ end
28
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 1 argument, but the Regexp matched 0 arguments.")
29
+ end
30
+
31
+ it "should raise ArityMismatchError for too few args (expecting 2)" do
32
+ lambda {
33
+ Object.new.cucumber_instance_exec(true, 'foo', 1) do |a,b|
34
+ end
35
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 2 arguments, but the Regexp matched 1 argument.")
36
+ end
37
+
38
+ if Cucumber::RUBY_1_9
39
+ it "should allow varargs" do
40
+ lambda {
41
+ Object.new.cucumber_instance_exec(true, 'foo', 1) do |*args|
42
+ end
43
+ }.should_not raise_error(Cucumber::ArityMismatchError)
44
+ end
45
+ else
46
+ # Ruby 1.8
47
+ it "should not allow varargs because Ruby 1.8 reports same arity as with no args, so we can't really tell the difference." do
48
+ lambda {
49
+ Object.new.cucumber_instance_exec(true, 'foo', 1) do |*args|
50
+ end
51
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 0 arguments, but the Regexp matched 1 argument.")
52
+ end
53
+ end
54
+ end
@@ -13,19 +13,11 @@ module Cucumber
13
13
  end
14
14
 
15
15
  def parse_file(file)
16
- @parser.parse_file(File.dirname(__FILE__) + "/../treetop_parser/" + file)
16
+ @parser.parse_file(File.dirname(__FILE__) + "/../treetop_parser/" + file, {})
17
17
  end
18
18
 
19
19
  def parse_example_file(file)
20
- @parser.parse_file(File.dirname(__FILE__) + "/../../../examples/" + file)
21
- end
22
-
23
- describe "Header" do
24
- it "should parse Feature with blurb" do
25
- parse(%{Feature: hi
26
- with blurb
27
- })
28
- end
20
+ @parser.parse_file(File.dirname(__FILE__) + "/../../../examples/" + file, {})
29
21
  end
30
22
 
31
23
  describe "Comments" do
@@ -36,23 +28,6 @@ Feature: hi
36
28
  [:feature, nil, "Feature: hi\n",
37
29
  [:comment, "# My comment\n"]]
38
30
  end
39
-
40
- it "should parse a comment within a scenario" do
41
- pending "Store comment in node and output it in pretty formatter"
42
- parse(%{Feature: Hi
43
- Scenario: Hello
44
- Given foo
45
- # When bar
46
- Then baz
47
- }).to_sexp.should ==
48
- [:feature, nil, "Feature: Hi",
49
- [:scenario, 2, "Scenario:", "Hello",
50
- [:step, 3, "Given", "foo"],
51
- [:comment, "# When bar\n"],
52
- [:step, 5, "Then", "baz"]
53
- ]
54
- ]
55
- end
56
31
 
57
32
  it "should parse a file with only a multiline comment" do
58
33
  parse(%{# Hello
@@ -149,7 +124,7 @@ Given I have a table
149
124
  [:scenario, 2, "Scenario:", "Hello",
150
125
  [:step_invocation, 3, "Given", "I have a table",
151
126
  [:table,
152
- [:row,
127
+ [:row, 4,
153
128
  [:cell, "a"],
154
129
  [:cell, "b"]]]]]]
155
130
  end
@@ -187,9 +162,10 @@ Examples:
187
162
  [:step, 3, "Given", "a <what> cucumber"],
188
163
  [:examples, "Examples:", "",
189
164
  [:table,
190
- [:row,
165
+ [:row, 5,
191
166
  [:cell, "what"]],
192
- [:row, [:cell, "green"]]]]]]
167
+ [:row, 6,
168
+ [:cell, "green"]]]]]]
193
169
  end
194
170
 
195
171
  it "should have line numbered steps with inline table" do
@@ -207,15 +183,15 @@ Examples:
207
183
  [:scenario_outline, "Scenario Outline:", "Hello",
208
184
  [:step, 4, "Given", "I have a table",
209
185
  [:table,
210
- [:row,
186
+ [:row, 6,
211
187
  [:cell, "<a>"],
212
188
  [:cell, "<b>"]]]],
213
189
  [:examples, "Examples:", "",
214
190
  [:table,
215
- [:row,
191
+ [:row, 8,
216
192
  [:cell, "a"],
217
193
  [:cell, "b"]],
218
- [:row,
194
+ [:row, 9,
219
195
  [:cell, "c"],
220
196
  [:cell, "d"]]]]]]
221
197
  end
@@ -237,23 +213,18 @@ Examples:
237
213
  [:scenario_outline, "Scenario Outline:", "Hello",
238
214
  [:step, 5, "Given", "I have a table",
239
215
  [:table,
240
- [:row,
216
+ [:row, 6,
241
217
  [:cell, "1"],
242
218
  [:cell, "2"]]]],
243
219
  [:examples, "Examples:", "",
244
220
  [:table,
245
- [:row,
221
+ [:row, 9,
246
222
  [:cell, "x"],
247
223
  [:cell, "y"]],
248
- [:row,
224
+ [:row, 10,
249
225
  [:cell, "5"],
250
226
  [:cell, "6"]]]]]]
251
227
  end
252
-
253
- it "should set line numbers on feature" do
254
- feature = parse_file("empty_feature.feature:11:12")
255
- feature.instance_variable_get('@lines').should == [11, 12]
256
- end
257
228
  end
258
229
 
259
230
  describe "Syntax" do
@@ -277,6 +248,37 @@ Examples:
277
248
  parse_file("scenario_outline.feature")
278
249
  end
279
250
  end
251
+
252
+ describe "Filtering" do
253
+ it "should filter outline tables" do
254
+ f = parse_example_file('self_test/features/outline_sample.feature:12')
255
+ f.to_sexp.should ==
256
+ [:feature,
257
+ "./spec/cucumber/parser/../../../examples/self_test/features/outline_sample.feature",
258
+ "Feature: Outline Sample",
259
+ [:scenario_outline,
260
+ "Scenario Outline:",
261
+ "Test state",
262
+ [:step, 6, "Given", "<state> without a table"],
263
+ [:step, 7, "Given", "<other_state> without a table"],
264
+ [:examples,
265
+ "Examples:",
266
+ "Rainbow colours",
267
+ [:table,
268
+ [:row, 9, [:cell, "state"], [:cell, "other_state"]],
269
+ # [:row, 10, [:cell, "missing"], [:cell, "passing"]],
270
+ # [:row, 11, [:cell, "passing"], [:cell, "passing"]],
271
+ [:row, 12, [:cell, "failing"], [:cell, "passing"]]]]
272
+ # ,
273
+ # [:examples,
274
+ # "Examples:",
275
+ # "Only passing",
276
+ # [:table,
277
+ # [:row, 14, [:cell, "state"], [:cell, "other_state"]],
278
+ # [:row, 15, [:cell, "passing"], [:cell, "passing"]]]]]
279
+ ]]
280
+ end
281
+ end
280
282
  end
281
283
  end
282
284
  end
@@ -27,8 +27,8 @@ module Cucumber
27
27
  @step_mother.step_match("Three blind mice")
28
28
  end.should raise_error(Ambiguous, %{Ambiguous match of "Three blind mice":
29
29
 
30
- specs/cucumber/step_mother_spec.rb:23:in `/Three (.*) mice/'
31
- specs/cucumber/step_mother_spec.rb:24:in `/Three blind (.*)/'
30
+ spec/cucumber/step_mother_spec.rb:23:in `/Three (.*) mice/'
31
+ spec/cucumber/step_mother_spec.rb:24:in `/Three blind (.*)/'
32
32
 
33
33
  You can run again with --guess to make Cucumber be more smart about it
34
34
  })
@@ -43,8 +43,8 @@ You can run again with --guess to make Cucumber be more smart about it
43
43
  @step_mother.step_match("Three cute mice")
44
44
  end.should raise_error(Ambiguous, %{Ambiguous match of "Three cute mice":
45
45
 
46
- specs/cucumber/step_mother_spec.rb:39:in `/Three (.*) mice/'
47
- specs/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
46
+ spec/cucumber/step_mother_spec.rb:39:in `/Three (.*) mice/'
47
+ spec/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
48
48
 
49
49
  })
50
50
  end
@@ -85,5 +85,64 @@ specs/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
85
85
  @step_mother.Given(/Three (.*) mice/) {|disability|}
86
86
  end.should raise_error(Redundant)
87
87
  end
88
+
89
+ it "should raise an error if the world is nil" do
90
+ @step_mother.World do
91
+ end
92
+
93
+ begin
94
+ @step_mother.before_and_after(nil)
95
+ raise "Should fail"
96
+ rescue NilWorld => e
97
+ e.message.should == "World procs should never return nil"
98
+ e.backtrace.should == ["spec/cucumber/step_mother_spec.rb:90:in `World'"]
99
+ end
100
+ end
101
+
102
+ module ModuleOne
103
+ end
104
+
105
+ module ModuleTwo
106
+ end
107
+
108
+ class ClassOne
109
+ end
110
+
111
+ it "should implicitly extend world with modules" do
112
+ @step_mother.World(ModuleOne, ModuleTwo)
113
+
114
+ w = @step_mother.__send__(:new_world!)
115
+ class << w
116
+ included_modules.index(ModuleOne).should_not == nil
117
+ included_modules.index(ModuleTwo).should_not == nil
118
+ end
119
+ w.class.should == Object
120
+ end
121
+
122
+ it "should raise error when we try to register more than one World proc" do
123
+ @step_mother.World { Hash.new }
124
+ lambda do
125
+ @step_mother.World { Array.new }
126
+ end.should raise_error(MultipleWorld, %{You can only pass a proc to #World once, but it's happening
127
+ in 2 places:
128
+
129
+ spec/cucumber/step_mother_spec.rb:123:in `World'
130
+ spec/cucumber/step_mother_spec.rb:125:in `World'
131
+
132
+ Use Ruby modules instead to extend your worlds. See the #World RDoc.
133
+
134
+ })
135
+ end
136
+
137
+ it "should find before hooks" do
138
+ fish = @step_mother.Before('@fish'){}
139
+ meat = @step_mother.Before('@meat'){}
140
+
141
+ scenario = mock('Scenario')
142
+ scenario.should_receive(:accept_hook?).with(fish).and_return(true)
143
+ scenario.should_receive(:accept_hook?).with(meat).and_return(false)
144
+
145
+ @step_mother.hooks_for(:before, scenario).should == [fish]
146
+ end
88
147
  end
89
148
  end