kosmas58-cucumber 0.2.2.1 → 0.2.3.3

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 (101) hide show
  1. data/History.txt +57 -5
  2. data/Manifest.txt +21 -4
  3. data/bin/cucumber +1 -1
  4. data/config/hoe.rb +2 -2
  5. data/examples/i18n/Rakefile +6 -8
  6. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -1
  7. data/examples/i18n/ar/lib/calculator.rb +1 -0
  8. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +1 -1
  9. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +1 -1
  10. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +1 -1
  11. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +1 -1
  12. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +1 -1
  13. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +1 -1
  14. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +1 -1
  15. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +1 -1
  16. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +1 -1
  17. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +1 -1
  18. data/examples/i18n/ko/features/addition.feature +1 -1
  19. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +1 -1
  20. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +1 -1
  21. data/examples/i18n/no/features/support/env.rb +1 -1
  22. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +1 -1
  23. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +1 -1
  24. data/examples/i18n/ru/features/support/env.rb +1 -1
  25. data/examples/i18n/ru/features/support/world.rb +4 -3
  26. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +1 -1
  27. data/examples/i18n/sk/Rakefile +6 -0
  28. data/examples/i18n/sk/features/addition.feature +16 -0
  29. data/examples/i18n/sk/features/division.feature +9 -0
  30. data/examples/i18n/sk/features/step_definitons/calculator_steps.rb +24 -0
  31. data/examples/i18n/sk/lib/calculator.rb +14 -0
  32. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +1 -1
  33. data/examples/i18n/zh-TW/features/step_definitons/calculator_steps.rb +1 -1
  34. data/examples/self_test/features/background/background_with_name.feature +7 -0
  35. data/examples/self_test/features/step_definitions/sample_steps.rb +8 -2
  36. data/examples/self_test/features/undefined_multiline_args.feature +12 -0
  37. data/examples/sinatra/features/support/env.rb +2 -6
  38. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +1 -4
  39. data/examples/tickets/Rakefile +1 -1
  40. data/examples/tickets/features/246.feature +4 -0
  41. data/examples/tickets/features/270/back.feature +14 -0
  42. data/examples/tickets/features/270/back.steps.rb +14 -0
  43. data/examples/tickets/features/step_definitons/246_steps.rb +3 -0
  44. data/features/background.feature +21 -4
  45. data/features/cucumber_cli.feature +18 -5
  46. data/features/cucumber_cli_outlines.feature +5 -2
  47. data/features/snippet.feature +23 -0
  48. data/features/step_definitions/cucumber_steps.rb +6 -2
  49. data/features/usage.feature +5 -0
  50. data/gem_tasks/rspec.rake +3 -2
  51. data/lib/cucumber/ast/background.rb +3 -3
  52. data/lib/cucumber/ast/examples.rb +0 -12
  53. data/lib/cucumber/ast/feature.rb +2 -12
  54. data/lib/cucumber/ast/feature_element.rb +0 -8
  55. data/lib/cucumber/ast/features.rb +1 -1
  56. data/lib/cucumber/ast/outline_table.rb +14 -22
  57. data/lib/cucumber/ast/py_string.rb +6 -11
  58. data/lib/cucumber/ast/scenario.rb +1 -8
  59. data/lib/cucumber/ast/scenario_outline.rb +1 -11
  60. data/lib/cucumber/ast/step.rb +3 -9
  61. data/lib/cucumber/ast/step_collection.rb +0 -4
  62. data/lib/cucumber/ast/step_invocation.rb +5 -6
  63. data/lib/cucumber/ast/table.rb +26 -22
  64. data/lib/cucumber/ast/tags.rb +0 -8
  65. data/lib/cucumber/ast/visitor.rb +12 -25
  66. data/lib/cucumber/cli/configuration.rb +2 -2
  67. data/lib/cucumber/cli/main.rb +5 -2
  68. data/lib/cucumber/core_ext/instance_exec.rb +17 -4
  69. data/lib/cucumber/formatter/ansicolor.rb +10 -2
  70. data/lib/cucumber/formatter/console.rb +2 -1
  71. data/lib/cucumber/formatter/html.rb +21 -7
  72. data/lib/cucumber/formatter/pretty.rb +27 -20
  73. data/lib/cucumber/formatter/usage.rb +16 -0
  74. data/lib/cucumber/languages.yml +68 -7
  75. data/lib/cucumber/parser/feature.rb +238 -135
  76. data/lib/cucumber/parser/feature.tt +117 -22
  77. data/lib/cucumber/parser/i18n.tt +4 -0
  78. data/lib/cucumber/parser/table.rb +37 -25
  79. data/lib/cucumber/parser/table.tt +15 -3
  80. data/lib/cucumber/parser/treetop_ext.rb +48 -9
  81. data/lib/cucumber/parser.rb +2 -7
  82. data/lib/cucumber/step_definition.rb +13 -14
  83. data/lib/cucumber/step_mother.rb +93 -11
  84. data/lib/cucumber/version.rb +2 -2
  85. data/rails_generators/cucumber/templates/env.rb +1 -1
  86. data/rails_generators/cucumber/templates/paths.rb +15 -5
  87. data/rails_generators/cucumber/templates/webrat_steps.rb +8 -0
  88. data/spec/cucumber/ast/background_spec.rb +1 -0
  89. data/spec/cucumber/ast/feature_factory.rb +1 -1
  90. data/spec/cucumber/ast/feature_spec.rb +2 -2
  91. data/spec/cucumber/ast/scenario_spec.rb +0 -27
  92. data/spec/cucumber/ast/table_spec.rb +23 -2
  93. data/spec/cucumber/core_ext/proc_spec.rb +25 -8
  94. data/spec/cucumber/parser/feature_parser_spec.rb +43 -41
  95. data/spec/cucumber/step_definition_spec.rb +8 -0
  96. data/spec/cucumber/step_mother_spec.rb +48 -0
  97. data/spec/spec_helper.rb +2 -11
  98. metadata +17 -6
  99. data/examples/tickets/cucumber.yml +0 -3
  100. data/lib/cucumber/parser/basic.rb +0 -0
  101. data/spec/cucumber/ast/tags_spec.rb +0 -19
@@ -45,6 +45,23 @@ module Cucumber
45
45
  end
46
46
  end
47
47
 
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 #World RDoc.\n\n"
61
+ super(message)
62
+ end
63
+ end
64
+
48
65
  # This is the main interface for registering step definitions, which is done
49
66
  # from <tt>*_steps.rb</tt> files. This module is included right at the top-level
50
67
  # so #register_step_definition (and more interestingly - its aliases) are
@@ -105,10 +122,46 @@ module Cucumber
105
122
  (@after_procs ||= []).unshift(proc)
106
123
  end
107
124
 
108
- # Registers a World proc. You can call this method as many times as you
109
- # want (typically from ruby scripts under <tt>support</tt>).
110
- def World(&proc)
111
- (@world_procs ||= []) << proc
125
+ # Registers any number of +world_modules+ (Ruby Modules) and/or a Proc.
126
+ # The +proc+ will be executed once before each scenario to create an
127
+ # Object that the scenario's steps will run within. Any +world_modules+
128
+ # will be mixed into this Object (via Object#extend).
129
+ #
130
+ # This method is typically called from one or more Ruby scripts under
131
+ # <tt>features/support</tt>. You can call this method as many times as you
132
+ # like (to register more modules), but if you try to register more than
133
+ # one Proc you will get an error.
134
+ #
135
+ # Cucumber will not yield anything to the +proc+ (like it used to do before v0.3).
136
+ #
137
+ # In earlier versions of Cucumber (before 0.3) you could not register
138
+ # any +world_modules+. Instead you would register several Proc objects (by
139
+ # calling the method several times). The result of each +proc+ would be yielded
140
+ # to the next +proc+. Example:
141
+ #
142
+ # World do |world| # NOT SUPPORTED FROM 0.3
143
+ # MyClass.new
144
+ # end
145
+ #
146
+ # World do |world| # NOT SUPPORTED FROM 0.3
147
+ # world.extend(MyModule)
148
+ # end
149
+ #
150
+ # From Cucumber 0.3 the recommended way to do this is:
151
+ #
152
+ # World do
153
+ # MyClass.new
154
+ # end
155
+ #
156
+ # World(MyModule)
157
+ #
158
+ def World(*world_modules, &proc)
159
+ if(proc)
160
+ raise MultipleWorld.new(@world_proc, proc) if @world_proc
161
+ @world_proc = proc
162
+ end
163
+ @world_modules ||= []
164
+ @world_modules += world_modules
112
165
  end
113
166
 
114
167
  def current_world
@@ -139,8 +192,8 @@ module Cucumber
139
192
  @step_definitions ||= []
140
193
  end
141
194
 
142
- def snippet_text(step_keyword, step_name)
143
- @snippet_generator.snippet_text(step_keyword, step_name)
195
+ def snippet_text(step_keyword, step_name, multiline_arg_class)
196
+ @snippet_generator.snippet_text(step_keyword, step_name, multiline_arg_class)
144
197
  end
145
198
 
146
199
  def before_and_after(scenario, skip=false)
@@ -168,17 +221,46 @@ module Cucumber
168
221
 
169
222
  # Creates a new world instance
170
223
  def new_world!
171
- @current_world = Object.new
172
- (@world_procs ||= []).each do |proc|
173
- @current_world = proc.call(@current_world)
224
+ create_world!
225
+ extend_world
226
+ connect_world
227
+ @current_world
228
+ end
229
+
230
+ def create_world!
231
+ if(@world_proc)
232
+ @current_world = @world_proc.call
233
+ check_nil(@current_world, @world_proc)
234
+ else
235
+ @current_world = Object.new
174
236
  end
237
+ end
175
238
 
239
+ def extend_world
176
240
  @current_world.extend(World)
241
+ @current_world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
242
+ (@world_modules || []).each do |mod|
243
+ @current_world.extend(mod)
244
+ end
245
+ end
246
+
247
+ def connect_world
177
248
  @current_world.__cucumber_step_mother = self
178
249
  @current_world.__cucumber_visitor = @visitor
250
+ end
179
251
 
180
- @current_world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
181
- @current_world
252
+ def check_nil(o, proc)
253
+ if o.nil?
254
+ begin
255
+ raise NilWorld.new
256
+ rescue NilWorld => e
257
+ e.backtrace.clear
258
+ e.backtrace.push(proc.backtrace_line("World"))
259
+ raise e
260
+ end
261
+ else
262
+ o
263
+ end
182
264
  end
183
265
 
184
266
  def nil_world!
@@ -2,8 +2,8 @@ module Cucumber #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
6
- PATCH = 1 # Set to nil for official release
5
+ TINY = 3
6
+ PATCH = 3 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -2,7 +2,7 @@
2
2
  ENV["RAILS_ENV"] ||= "test"
3
3
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4
4
  require 'cucumber/rails/world'
5
- require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
5
+ require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
6
6
  Cucumber::Rails.use_transactional_fixtures
7
7
  Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
8
8
  # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
@@ -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
 
@@ -8,12 +20,10 @@ module NavigationHelpers
8
20
  # Add more page name => path mappings here
9
21
 
10
22
  else
11
- raise "Can't find mapping from \"#{page_name}\" to a path."
23
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
24
+ "Now, go and add a mapping in features/support/paths.rb"
12
25
  end
13
26
  end
14
27
  end
15
28
 
16
- World do |world|
17
- world.extend NavigationHelpers
18
- world
19
- end
29
+ World(NavigationHelpers)
@@ -113,3 +113,11 @@ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
113
113
  assert field_labeled(label).checked?
114
114
  <% end -%>
115
115
  end
116
+
117
+ Then /^I should be on (.+)$/ do |page_name|
118
+ <% if framework == :rspec -%>
119
+ URI.parse(current_url).path.should == path_to(page_name)
120
+ <% else -%>
121
+ assert_equal path_to(page_name), URI.parse(current_url).path
122
+ <% end -%>
123
+ end
@@ -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
@@ -69,6 +69,27 @@ module Cucumber
69
69
  @table.transpose.hashes[0].should == {'one' => '1111', 'two' => '22222'}
70
70
  end
71
71
  end
72
+
73
+ describe ".rows_hash" do
74
+
75
+ it "should return a hash of the rows" do
76
+ table = Table.new([
77
+ %w{one 1111},
78
+ %w{two 22222}
79
+ ])
80
+ table.rows_hash.should == {'one' => '1111', 'two' => '22222'}
81
+ end
82
+
83
+ it "should fail if the table doesn't have two columns" do
84
+ faulty_table = Table.new([
85
+ %w{one 1111 abc},
86
+ %w{two 22222 def}
87
+ ])
88
+ lambda {
89
+ faulty_table.rows_hash
90
+ }.should raise_error('The table must have exactly 2 columns')
91
+ end
92
+ end
72
93
 
73
94
  it "should allow renaming columns" do
74
95
  table2 = @table.map_headers('one' => :three)
@@ -134,12 +155,12 @@ module Cucumber
134
155
  it "should convert to sexp" do
135
156
  @table.to_sexp.should ==
136
157
  [:table,
137
- [:row,
158
+ [:row, -1,
138
159
  [:cell, "one"],
139
160
  [:cell, "four"],
140
161
  [:cell, "seven"]
141
162
  ],
142
- [:row,
163
+ [:row, -1,
143
164
  [:cell, "4444"],
144
165
  [:cell, "55555"],
145
166
  [:cell, "666666"]]]
@@ -2,36 +2,53 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
  require 'cucumber/core_ext/instance_exec'
3
3
 
4
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
+
5
10
  it "should raise ArityMismatchError for too many args (expecting 0)" do
6
11
  lambda {
7
12
  Object.new.cucumber_instance_exec(true, 'foo', 1) do
8
13
  end
9
- }.should raise_error(Cucumber::ArityMismatchError, "expected 0 block argument(s), got 1")
14
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 0 arguments, but the Regexp matched 1 argument.")
10
15
  end
11
16
 
12
17
  it "should raise ArityMismatchError for too many args (expecting 1)" do
13
18
  lambda {
14
19
  Object.new.cucumber_instance_exec(true, 'foo', 1,2) do |a|
15
20
  end
16
- }.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 2")
21
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 1 argument, but the Regexp matched 2 arguments.")
17
22
  end
18
23
 
19
24
  it "should raise ArityMismatchError for too few args (expecting 1)" do
20
25
  lambda {
21
26
  Object.new.cucumber_instance_exec(true, 'foo') do |a|
22
27
  end
23
- }.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 0")
28
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 1 argument, but the Regexp matched 0 arguments.")
24
29
  end
25
30
 
26
31
  it "should raise ArityMismatchError for too few args (expecting 2)" do
27
32
  lambda {
28
33
  Object.new.cucumber_instance_exec(true, 'foo', 1) do |a,b|
29
34
  end
30
- }.should raise_error(Cucumber::ArityMismatchError, "expected 2 block argument(s), got 1")
35
+ }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 2 arguments, but the Regexp matched 1 argument.")
31
36
  end
32
-
33
- it "should remove extraneous path info for file" do
34
- proc = lambda {|a,b|}
35
- proc.file_colon_line.should == "spec/cucumber/core_ext/proc_spec.rb:34"
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
36
53
  end
37
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
@@ -82,6 +82,14 @@ module Cucumber
82
82
  })
83
83
  end
84
84
 
85
+ it "should recognise several quoted words in name and make according regexp and args" do
86
+ StepDefinition.snippet_text('Given', 'A "first" and "second" arg').should == unindented(%{
87
+ Given /^A "([^\\"]*)" and "([^\\"]*)" arg$/ do |arg1, arg2|
88
+ pending
89
+ end
90
+ })
91
+ end
92
+
85
93
  it "should not use quote group when there are no quotes" do
86
94
  StepDefinition.snippet_text('Given', 'A first arg').should == unindented(%{
87
95
  Given /^A first arg$/ do
@@ -85,5 +85,53 @@ spec/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
88
136
  end
89
137
  end
data/spec/spec_helper.rb CHANGED
@@ -1,21 +1,12 @@
1
1
  require 'rubygems'
2
2
  gem 'rspec'
3
- require 'spec/expectations'
3
+ require 'spec'
4
+ require 'spec/autorun'
4
5
 
5
6
  ENV['CUCUMBER_COLORS']=nil
6
- $KCODE='u'
7
7
  $:.unshift(File.dirname(__FILE__) + '/../lib')
8
8
  require 'cucumber'
9
9
  Cucumber.load_language('en')
10
10
  $:.unshift(File.dirname(__FILE__))
11
11
 
12
12
  ::Term::ANSIColor.coloring = true
13
-
14
- # Open up the tree classes a little for easier inspection.
15
- module Cucumber
16
- module Tree
17
- class Feature
18
- attr_reader :header, :scenarios
19
- end
20
- end
21
- end