cucumber 0.8.5 → 0.8.6

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 (181) hide show
  1. data/.rspec +1 -1
  2. data/LICENSE +1 -1
  3. data/Rakefile +5 -51
  4. data/bin/cucumber +7 -1
  5. data/cucumber.gemspec +463 -679
  6. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -1
  7. data/examples/i18n/he/features/step_definitons/calculator_steps.rb +1 -1
  8. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +4 -7
  9. data/examples/i18n/ru/features/division.feature +2 -2
  10. data/examples/i18n/tr/features/step_definitons/hesap_makinesi_adimlari.rb +3 -3
  11. data/examples/sinatra/features/support/env.rb +2 -5
  12. data/examples/v8/features/fibonacci.feature +1 -1
  13. data/examples/watir/features/step_definitions/search_steps.rb +1 -1
  14. data/features/background.feature +284 -95
  15. data/features/custom_formatter.feature +3 -73
  16. data/features/json_formatter.feature +160 -245
  17. data/features/step_definitions/cucumber_steps.rb +7 -153
  18. data/features/support/env.rb +18 -140
  19. data/fixtures/junit/features/pending.feature +3 -1
  20. data/fixtures/self_test/features/support/env.rb +8 -0
  21. data/fixtures/tickets/features.html +1 -1
  22. data/gem_tasks/examples.rake +1 -1
  23. data/lib/cucumber.rb +12 -0
  24. data/lib/cucumber/ast.rb +1 -1
  25. data/lib/cucumber/ast/background.rb +21 -5
  26. data/lib/cucumber/ast/examples.rb +12 -4
  27. data/lib/cucumber/ast/feature.rb +13 -5
  28. data/lib/cucumber/ast/feature_element.rb +9 -4
  29. data/lib/cucumber/ast/outline_table.rb +4 -4
  30. data/lib/cucumber/ast/scenario.rb +7 -5
  31. data/lib/cucumber/ast/scenario_outline.rb +23 -15
  32. data/lib/cucumber/ast/step.rb +5 -0
  33. data/lib/cucumber/ast/step_invocation.rb +21 -15
  34. data/lib/cucumber/ast/table.rb +14 -8
  35. data/lib/cucumber/ast/tree_walker.rb +10 -48
  36. data/lib/cucumber/cli/configuration.rb +33 -8
  37. data/lib/cucumber/cli/main.rb +20 -35
  38. data/lib/cucumber/cli/options.rb +8 -7
  39. data/lib/cucumber/cli/profile_loader.rb +2 -0
  40. data/lib/cucumber/core_ext/proc.rb +2 -1
  41. data/lib/cucumber/feature_file.rb +47 -15
  42. data/lib/cucumber/formatter/ansicolor.rb +3 -5
  43. data/lib/cucumber/formatter/console.rb +27 -23
  44. data/lib/cucumber/formatter/cucumber.css +34 -17
  45. data/lib/cucumber/formatter/cucumber.sass +173 -182
  46. data/lib/cucumber/formatter/html.rb +46 -11
  47. data/lib/cucumber/formatter/io.rb +2 -4
  48. data/lib/cucumber/formatter/json.rb +15 -152
  49. data/lib/cucumber/formatter/json_pretty.rb +5 -6
  50. data/lib/cucumber/formatter/junit.rb +28 -22
  51. data/lib/cucumber/formatter/pdf.rb +6 -6
  52. data/lib/cucumber/formatter/pretty.rb +5 -5
  53. data/lib/cucumber/formatter/rerun.rb +22 -11
  54. data/lib/cucumber/formatter/unicode.rb +41 -20
  55. data/lib/cucumber/js_support/js_dsl.js +4 -4
  56. data/lib/cucumber/js_support/js_language.rb +9 -5
  57. data/lib/cucumber/js_support/js_snippets.rb +2 -2
  58. data/lib/cucumber/language_support.rb +2 -2
  59. data/lib/cucumber/parser/gherkin_builder.rb +35 -30
  60. data/lib/cucumber/platform.rb +8 -8
  61. data/lib/cucumber/py_support/py_language.rb +2 -2
  62. data/lib/cucumber/rake/task.rb +80 -31
  63. data/lib/cucumber/rb_support/rb_dsl.rb +1 -0
  64. data/lib/cucumber/rb_support/rb_language.rb +10 -8
  65. data/lib/cucumber/rb_support/rb_step_definition.rb +8 -0
  66. data/lib/cucumber/rb_support/rb_transform.rb +17 -0
  67. data/lib/cucumber/rb_support/rb_world.rb +26 -18
  68. data/lib/cucumber/rspec/doubles.rb +3 -3
  69. data/lib/cucumber/step_match.rb +6 -2
  70. data/lib/cucumber/step_mother.rb +6 -427
  71. data/lib/cucumber/wire_support/configuration.rb +4 -1
  72. data/lib/cucumber/wire_support/wire_language.rb +3 -10
  73. data/spec/cucumber/ast/background_spec.rb +68 -6
  74. data/spec/cucumber/ast/feature_factory.rb +5 -4
  75. data/spec/cucumber/ast/feature_spec.rb +4 -4
  76. data/spec/cucumber/ast/outline_table_spec.rb +1 -1
  77. data/spec/cucumber/ast/scenario_outline_spec.rb +15 -11
  78. data/spec/cucumber/ast/scenario_spec.rb +4 -4
  79. data/spec/cucumber/ast/step_spec.rb +3 -3
  80. data/spec/cucumber/ast/table_spec.rb +38 -2
  81. data/spec/cucumber/ast/tree_walker_spec.rb +2 -2
  82. data/spec/cucumber/broadcaster_spec.rb +1 -1
  83. data/spec/cucumber/cli/configuration_spec.rb +32 -6
  84. data/spec/cucumber/cli/drb_client_spec.rb +2 -3
  85. data/spec/cucumber/cli/main_spec.rb +43 -43
  86. data/spec/cucumber/cli/options_spec.rb +28 -1
  87. data/spec/cucumber/cli/profile_loader_spec.rb +1 -1
  88. data/spec/cucumber/core_ext/proc_spec.rb +1 -1
  89. data/spec/cucumber/formatter/ansicolor_spec.rb +1 -1
  90. data/spec/cucumber/formatter/duration_spec.rb +1 -1
  91. data/spec/cucumber/formatter/html_spec.rb +3 -5
  92. data/spec/cucumber/formatter/junit_spec.rb +16 -2
  93. data/spec/cucumber/formatter/progress_spec.rb +1 -1
  94. data/spec/cucumber/formatter/spec_helper.rb +11 -12
  95. data/spec/cucumber/rb_support/rb_language_spec.rb +241 -28
  96. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +33 -28
  97. data/spec/cucumber/rb_support/regexp_argument_matcher_spec.rb +1 -1
  98. data/spec/cucumber/step_match_spec.rb +11 -9
  99. data/spec/cucumber/wire_support/configuration_spec.rb +1 -1
  100. data/spec/cucumber/wire_support/connection_spec.rb +1 -1
  101. data/spec/cucumber/wire_support/wire_exception_spec.rb +1 -1
  102. data/spec/cucumber/wire_support/wire_language_spec.rb +1 -1
  103. data/spec/cucumber/wire_support/wire_packet_spec.rb +1 -1
  104. data/spec/cucumber/wire_support/wire_step_definition_spec.rb +1 -1
  105. data/spec/cucumber/world/pending_spec.rb +2 -2
  106. data/spec/spec_helper.rb +13 -20
  107. metadata +11 -222
  108. data/.gitignore +0 -20
  109. data/Caliper.yml +0 -4
  110. data/History.txt +0 -1552
  111. data/README.rdoc +0 -26
  112. data/VERSION.yml +0 -5
  113. data/examples/i18n/ro/features/suma.feature +0 -11
  114. data/features/announce.feature +0 -164
  115. data/features/around_hooks.feature +0 -232
  116. data/features/bug_371.feature +0 -32
  117. data/features/bug_464.feature +0 -16
  118. data/features/bug_475.feature +0 -42
  119. data/features/bug_585_tab_indentation.feature +0 -22
  120. data/features/bug_600.feature +0 -67
  121. data/features/call_steps_from_stepdefs.feature +0 -154
  122. data/features/cucumber_cli.feature +0 -591
  123. data/features/cucumber_cli_outlines.feature +0 -117
  124. data/features/default_snippets.feature +0 -42
  125. data/features/diffing.feature +0 -25
  126. data/features/drb_server_integration.feature +0 -174
  127. data/features/exception_in_after_block.feature +0 -127
  128. data/features/exception_in_after_step_block.feature +0 -104
  129. data/features/exception_in_before_block.feature +0 -98
  130. data/features/exclude_files.feature +0 -20
  131. data/features/expand.feature +0 -60
  132. data/features/html_formatter.feature +0 -8
  133. data/features/html_formatter/a.html +0 -582
  134. data/features/junit_formatter.feature +0 -88
  135. data/features/language_from_header.feature +0 -30
  136. data/features/language_help.feature +0 -78
  137. data/features/listener_debugger_formatter.feature +0 -42
  138. data/features/multiline_names.feature +0 -44
  139. data/features/negative_tagged_hooks.feature +0 -60
  140. data/features/post_configuration_hook.feature +0 -37
  141. data/features/profiles.feature +0 -126
  142. data/features/rake_task.feature +0 -152
  143. data/features/report_called_undefined_steps.feature +0 -34
  144. data/features/rerun_formatter.feature +0 -45
  145. data/features/simplest.feature +0 -11
  146. data/features/snippet.feature +0 -23
  147. data/features/snippets_when_using_star_keyword.feature +0 -36
  148. data/features/step_definitions/extra_steps.rb +0 -2
  149. data/features/step_definitions/simplest_steps.rb +0 -3
  150. data/features/step_definitions/wire_steps.rb +0 -32
  151. data/features/support/env.rb.simplest +0 -7
  152. data/features/support/fake_wire_server.rb +0 -77
  153. data/features/table_diffing.feature +0 -45
  154. data/features/table_mapping.feature +0 -34
  155. data/features/tag_logic.feature +0 -258
  156. data/features/transform.feature +0 -245
  157. data/features/unicode_table.feature +0 -35
  158. data/features/usage_and_stepdefs_formatter.feature +0 -169
  159. data/features/wire_protocol.feature +0 -332
  160. data/features/wire_protocol_table_diffing.feature +0 -119
  161. data/features/wire_protocol_tags.feature +0 -87
  162. data/features/wire_protocol_timeouts.feature +0 -63
  163. data/features/work_in_progress.feature +0 -156
  164. data/fixtures/json/features/pystring.feature +0 -8
  165. data/fixtures/self_test/features/background/background_tagged_before_on_outline.feature +0 -12
  166. data/fixtures/self_test/features/background/background_with_name.feature +0 -7
  167. data/fixtures/self_test/features/background/failing_background.feature +0 -12
  168. data/fixtures/self_test/features/background/failing_background_after_success.feature +0 -11
  169. data/fixtures/self_test/features/background/multiline_args_background.feature +0 -32
  170. data/fixtures/self_test/features/background/passing_background.feature +0 -10
  171. data/fixtures/self_test/features/background/pending_background.feature +0 -10
  172. data/fixtures/self_test/features/background/scenario_outline_failing_background.feature +0 -16
  173. data/fixtures/self_test/features/background/scenario_outline_passing_background.feature +0 -16
  174. data/gem_tasks/features.rake +0 -14
  175. data/gem_tasks/sdoc.rake +0 -12
  176. data/lib/cucumber/ast/py_string.rb +0 -80
  177. data/lib/cucumber/formatter/color_io.rb +0 -23
  178. data/lib/cucumber/formatter/tag_cloud.rb +0 -35
  179. data/spec/cucumber/ast/py_string_spec.rb +0 -40
  180. data/spec/cucumber/formatter/color_io_spec.rb +0 -29
  181. data/spec/cucumber/step_mother_spec.rb +0 -302
@@ -1,7 +0,0 @@
1
- Feature: background with name
2
-
3
- Background: I'm a background and I'm ok
4
- Given '10' cukes
5
-
6
- Scenario: example
7
- Then I should have '10' cukes
@@ -1,12 +0,0 @@
1
- @after_file
2
- Feature: Failing background sample
3
-
4
- Background:
5
- Given failing without a table
6
- And '10' cukes
7
-
8
- Scenario: failing background
9
- Then I should have '10' cukes
10
-
11
- Scenario: another failing background
12
- Then I should have '10' cukes
@@ -1,11 +0,0 @@
1
- Feature: Failing background after previously successful background sample
2
-
3
- Background:
4
- Given passing without a table
5
- And '10' global cukes
6
-
7
- Scenario: passing background
8
- Then I should have '10' global cukes
9
-
10
- Scenario: failing background
11
- Then I should have '10' global cukes
@@ -1,32 +0,0 @@
1
- Feature: Passing background with multiline args
2
-
3
- Background:
4
- Given table
5
- |a|b|
6
- |c|d|
7
- And multiline string
8
- """
9
- I'm a cucumber and I'm okay.
10
- I sleep all night and I test all day
11
- """
12
-
13
- Scenario: passing background
14
- Then the table should be
15
- |a|b|
16
- |c|d|
17
- Then the multiline string should be
18
- """
19
- I'm a cucumber and I'm okay.
20
- I sleep all night and I test all day
21
- """
22
-
23
- Scenario: another passing background
24
- Then the table should be
25
- |a|b|
26
- |c|d|
27
- Then the multiline string should be
28
- """
29
- I'm a cucumber and I'm okay.
30
- I sleep all night and I test all day
31
- """
32
-
@@ -1,10 +0,0 @@
1
- Feature: Passing background sample
2
-
3
- Background:
4
- Given '10' cukes
5
-
6
- Scenario: passing background
7
- Then I should have '10' cukes
8
-
9
- Scenario: another passing background
10
- Then I should have '10' cukes
@@ -1,10 +0,0 @@
1
- Feature: Pending background sample
2
-
3
- Background:
4
- Given pending
5
-
6
- Scenario: pending background
7
- Then I should have '10' cukes
8
-
9
- Scenario: another pending background
10
- Then I should have '10' cukes
@@ -1,16 +0,0 @@
1
- Feature: Failing background with scenario outlines sample
2
-
3
- Background:
4
- Given failing without a table
5
-
6
- Scenario Outline: failing background
7
- Then I should have '<count>' cukes
8
- Examples:
9
- |count|
10
- | 10 |
11
-
12
- Scenario Outline: another failing background
13
- Then I should have '<count>' cukes
14
- Examples:
15
- |count|
16
- | 10 |
@@ -1,16 +0,0 @@
1
- Feature: Passing background with scenario outlines sample
2
-
3
- Background:
4
- Given '10' cukes
5
-
6
- Scenario Outline: passing background
7
- Then I should have '<count>' cukes
8
- Examples:
9
- |count|
10
- | 10 |
11
-
12
- Scenario Outline: another passing background
13
- Then I should have '<count>' cukes
14
- Examples:
15
- |count|
16
- | 10 |
@@ -1,14 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'cucumber/rake/task'
3
- require 'cucumber/platform'
4
-
5
- Cucumber::Rake::Task.new do |t|
6
- if(Cucumber::JRUBY)
7
- t.profile = Cucumber::WINDOWS ? 'jruby_win' : 'jruby'
8
- elsif(Cucumber::WINDOWS_MRI)
9
- t.profile = 'windows_mri'
10
- elsif(Cucumber::RUBY_1_9)
11
- t.profile = 'ruby_1_9'
12
- end
13
- t.rcov = ENV['RCOV']
14
- end
data/gem_tasks/sdoc.rake DELETED
@@ -1,12 +0,0 @@
1
- begin
2
- require 'rake/rdoctask'
3
- require 'sdoc' # and use your RDoc task the same way you used it before
4
-
5
- Rake::RDocTask.new(:sdoc) do |rdoc|
6
- rdoc.rdoc_dir = 'doc/sdoc'
7
- rdoc.title = "Cucumber"
8
- rdoc.options += %w{--fmt shtml -N --webcvs=http://github.com/aslakhellesoy/cucumber/blob/v0.3.96/%s --title "Cucumber API" --threads 4 --main README --exclude cucumber/parser lib}
9
- rdoc.template = 'direct' # lighter template used on railsapi.com
10
- end
11
- rescue LoadError => ignore
12
- end
@@ -1,80 +0,0 @@
1
- module Cucumber
2
- module Ast
3
- # Represents an inline argument in a step. Example:
4
- #
5
- # Given the message
6
- # """
7
- # I like
8
- # Cucumber sandwich
9
- # """
10
- #
11
- # The text between the pair of <tt>"""</tt> is stored inside a PyString,
12
- # which is yielded to the StepDefinition block as the last argument.
13
- #
14
- # The StepDefinition can then access the String via the #to_s method. In the
15
- # example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
16
- #
17
- # Note how the indentation from the source is stripped away.
18
- #
19
- class PyString #:nodoc:
20
- class Builder
21
- attr_reader :string
22
-
23
- def initialize
24
- @string = ''
25
- end
26
-
27
- def py_string(string, line_number)
28
- @string = string
29
- end
30
-
31
- def eof
32
- end
33
- end
34
-
35
- attr_accessor :file
36
-
37
- def self.default_arg_name
38
- "string"
39
- end
40
-
41
- def self.parse(text)
42
- builder = Builder.new
43
- lexer = Gherkin::I18nLexer.new(builder)
44
- lexer.scan(text)
45
- new(builder.string)
46
- end
47
-
48
- def initialize(string)
49
- @string = string
50
- end
51
-
52
- def to_step_definition_arg
53
- @string
54
- end
55
-
56
- def accept(visitor)
57
- return if Cucumber.wants_to_quit
58
- visitor.visit_py_string(@string)
59
- end
60
-
61
- def arguments_replaced(arguments) #:nodoc:
62
- string = @string
63
- arguments.each do |name, value|
64
- value ||= ''
65
- string = string.gsub(name, value)
66
- end
67
- PyString.new(string)
68
- end
69
-
70
- def has_text?(text)
71
- @string.index(text)
72
- end
73
-
74
- # For testing only
75
- def to_sexp #:nodoc:
76
- [:py_string, to_step_definition_arg]
77
- end
78
- end
79
- end
80
- end
@@ -1,23 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Cucumber
4
- module Formatter
5
- # Adapter to make #puts/#print/#flush work with win32console
6
- class ColorIO #:nodoc:
7
- extend Forwardable
8
- def_delegators :@kernel, :puts, :print # win32console colours only work when sent to Kernel
9
- def_delegators :@stdout, :flush, :tty?, :write, :close
10
-
11
- def initialize(kernel, stdout)
12
- @kernel = kernel
13
- @stdout = stdout
14
- end
15
-
16
- # Ensure using << still gets colours in win32console
17
- def <<(output)
18
- print(output)
19
- self
20
- end
21
- end
22
- end
23
- end
@@ -1,35 +0,0 @@
1
- require 'cucumber/formatter/io'
2
- require 'cucumber/formatter/pretty'
3
-
4
- module Cucumber
5
- module Formatter
6
- # The formatter used for <tt>--format tag_cloud</tt>
7
- # Custom formatter that prints a tag cloud as a table.
8
- class TagCloud
9
- include Io
10
-
11
- def initialize(step_mother, path_or_io, options)
12
- @io = ensure_io(path_or_io, "tag_cloud")
13
- @options = options
14
- @counts = Hash.new{|h,k| h[k] = 0}
15
- end
16
-
17
- def after_features(features)
18
- print_summary(features)
19
- end
20
-
21
- def tag_name(tag_name)
22
- @counts[tag_name] += 1
23
- end
24
-
25
- private
26
-
27
- def print_summary(features)
28
- matrix = @counts.to_a.sort{|paira, pairb| paira[0] <=> pairb[0]}.transpose
29
- table = Cucumber::Ast::Table.new(matrix)
30
- formatter = Cucumber::Formatter::Pretty.new(@step_mother, @io, {})
31
- Cucumber::Ast::TreeWalker.new(@step_mother, [formatter], {}).visit_multiline_arg(table)
32
- end
33
- end
34
- end
35
- end
@@ -1,40 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require 'cucumber/ast/py_string'
3
-
4
- module Cucumber
5
- module Ast
6
- describe PyString do
7
- describe "replacing arguments" do
8
-
9
- before(:each) do
10
- @ps = PyString.new("<book>\n<qty>\n")
11
- end
12
-
13
- it "should return a new py_string with arguments replaced with values" do
14
- py_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere', '<qty>' => '5'})
15
-
16
- py_string_with_replaced_arg.to_step_definition_arg.should == "Life is elsewhere\n5\n"
17
- end
18
-
19
- it "should not change the original py_string" do
20
- py_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere'})
21
-
22
- @ps.to_s.should_not include("Life is elsewhere")
23
- end
24
-
25
- it "should replaced nil with empty string" do
26
- ps = PyString.new("'<book>'")
27
- py_string_with_replaced_arg = ps.arguments_replaced({'<book>' => nil})
28
-
29
- py_string_with_replaced_arg.to_step_definition_arg.should == "''"
30
- end
31
-
32
- it "should recognise when just a subset of a cell is delimited" do
33
- @ps.should have_text('<qty>')
34
- end
35
-
36
- end
37
-
38
- end
39
- end
40
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require 'cucumber/formatter/color_io'
3
-
4
- module Cucumber
5
- module Formatter
6
- describe ColorIO do
7
- describe "<<" do
8
- it "should convert to a print using kernel" do
9
- kernel = mock('Kernel')
10
- color_io = ColorIO.new(kernel, nil)
11
-
12
- kernel.should_receive(:print).with("monkeys")
13
-
14
- color_io << "monkeys"
15
- end
16
-
17
- it "should allow chained <<" do
18
- kernel = mock('Kernel')
19
- color_io = ColorIO.new(kernel, nil)
20
-
21
- kernel.should_receive(:print).with("monkeys")
22
- kernel.should_receive(:print).with(" are tasty")
23
-
24
- color_io << "monkeys" << " are tasty"
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,302 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- require 'cucumber'
4
- require 'cucumber/rb_support/rb_language'
5
-
6
- module Cucumber
7
- describe StepMother do
8
- before do
9
- @dsl = Object.new
10
- @dsl.extend(RbSupport::RbDsl)
11
-
12
- @step_mother = StepMother.new
13
-
14
- @rb = @step_mother.load_programming_language('rb')
15
-
16
- @visitor = mock('Visitor')
17
- end
18
-
19
- it "should format step names" do
20
- @dsl.Given(/it (.*) in (.*)/) do |what, month|
21
- end
22
- @dsl.Given(/nope something else/) do |what, month|
23
- end
24
-
25
- format = @step_mother.step_match("it snows in april").format_args("[%s]")
26
- format.should == "it [snows] in [april]"
27
- end
28
-
29
- it "should raise Ambiguous error with guess hint when multiple step definitions match" do
30
- @dsl.Given(/Three (.*) mice/) {|disability|}
31
- @dsl.Given(/Three blind (.*)/) {|animal|}
32
-
33
- lambda do
34
- @step_mother.step_match("Three blind mice")
35
- end.should raise_error(Ambiguous, %{Ambiguous match of "Three blind mice":
36
-
37
- spec/cucumber/step_mother_spec.rb:30:in `/Three (.*) mice/'
38
- spec/cucumber/step_mother_spec.rb:31:in `/Three blind (.*)/'
39
-
40
- You can run again with --guess to make Cucumber be more smart about it
41
- })
42
- end
43
-
44
- it "should not show --guess hint when --guess is used" do
45
- @step_mother.options = {:guess => true}
46
-
47
- @dsl.Given(/Three (.*) mice/) {|disability|}
48
- @dsl.Given(/Three cute (.*)/) {|animal|}
49
-
50
- lambda do
51
- @step_mother.step_match("Three cute mice")
52
- end.should raise_error(Ambiguous, %{Ambiguous match of "Three cute mice":
53
-
54
- spec/cucumber/step_mother_spec.rb:47:in `/Three (.*) mice/'
55
- spec/cucumber/step_mother_spec.rb:48:in `/Three cute (.*)/'
56
-
57
- })
58
- end
59
-
60
- it "should not raise Ambiguous error when multiple step definitions match, but --guess is enabled" do
61
- @step_mother.options = {:guess => true}
62
- @dsl.Given(/Three (.*) mice/) {|disability|}
63
- @dsl.Given(/Three (.*)/) {|animal|}
64
-
65
- lambda do
66
- @step_mother.step_match("Three blind mice")
67
- end.should_not raise_error
68
- end
69
-
70
- it "should not raise NoMethodError when guessing from multiple step definitions with nil fields" do
71
- @step_mother.options = {:guess => true}
72
- @dsl.Given(/Three (.*) mice( cannot find food)?/) {|disability, is_disastrous|}
73
- @dsl.Given(/Three (.*)?/) {|animal|}
74
-
75
- lambda do
76
- @step_mother.step_match("Three blind mice")
77
- end.should_not raise_error
78
- end
79
-
80
- it "should pick right step definition when --guess is enabled and equal number of capture groups" do
81
- @step_mother.options = {:guess => true}
82
- right = @dsl.Given(/Three (.*) mice/) {|disability|}
83
- wrong = @dsl.Given(/Three (.*)/) {|animal|}
84
-
85
- @step_mother.step_match("Three blind mice").step_definition.should == right
86
- end
87
-
88
- it "should pick right step definition when --guess is enabled and unequal number of capture groups" do
89
- @step_mother.options = {:guess => true}
90
- right = @dsl.Given(/Three (.*) mice ran (.*)/) {|disability|}
91
- wrong = @dsl.Given(/Three (.*)/) {|animal|}
92
-
93
- @step_mother.step_match("Three blind mice ran far").step_definition.should == right
94
- end
95
-
96
- it "should pick most specific step definition when --guess is enabled and unequal number of capture groups" do
97
- @step_mother.options = {:guess => true}
98
- general = @dsl.Given(/Three (.*) mice ran (.*)/) {|disability|}
99
- specific = @dsl.Given(/Three blind mice ran far/) do; end
100
- more_specific = @dsl.Given(/^Three blind mice ran far$/) do; end
101
-
102
- @step_mother.step_match("Three blind mice ran far").step_definition.should == more_specific
103
- end
104
-
105
- it "should raise Undefined error when no step definitions match" do
106
- lambda do
107
- @step_mother.step_match("Three blind mice")
108
- end.should raise_error(Undefined)
109
- end
110
-
111
- # http://railsforum.com/viewtopic.php?pid=93881
112
- it "should not raise Redundant unless it's really redundant" do
113
- @dsl.Given(/^(.*) (.*) user named '(.*)'$/) {|a,b,c|}
114
- @dsl.Given(/^there is no (.*) user named '(.*)'$/) {|a,b|}
115
- end
116
-
117
- it "should raise an error if the world is nil" do
118
- @dsl.World {}
119
-
120
- begin
121
- @step_mother.before_and_after(nil) do; end
122
- raise "Should fail"
123
- rescue RbSupport::NilWorld => e
124
- e.message.should == "World procs should never return nil"
125
- e.backtrace.should == ["spec/cucumber/step_mother_spec.rb:118:in `World'"]
126
- end
127
- end
128
-
129
- module ModuleOne
130
- end
131
-
132
- module ModuleTwo
133
- end
134
-
135
- class ClassOne
136
- end
137
-
138
- it "should implicitly extend world with modules" do
139
- @dsl.World(ModuleOne, ModuleTwo)
140
- @step_mother.before(mock('scenario').as_null_object)
141
- class << @rb.current_world
142
- included_modules.inspect.should =~ /ModuleOne/ # Workaround for RSpec/Ruby 1.9 issue with namespaces
143
- included_modules.inspect.should =~ /ModuleTwo/
144
- end
145
- @rb.current_world.class.should == Object
146
- end
147
-
148
- it "should raise error when we try to register more than one World proc" do
149
- @dsl.World { Hash.new }
150
- lambda do
151
- @dsl.World { Array.new }
152
- end.should raise_error(RbSupport::MultipleWorld, %{You can only pass a proc to #World once, but it's happening
153
- in 2 places:
154
-
155
- spec/cucumber/step_mother_spec.rb:149:in `World'
156
- spec/cucumber/step_mother_spec.rb:151:in `World'
157
-
158
- Use Ruby modules instead to extend your worlds. See the Cucumber::RbSupport::RbDsl#World RDoc
159
- or http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world.
160
-
161
- })
162
- end
163
-
164
- it "should find before hooks" do
165
- fish = @dsl.Before('@fish'){}
166
- meat = @dsl.Before('@meat'){}
167
-
168
- scenario = mock('Scenario')
169
- scenario.should_receive(:accept_hook?).with(fish).and_return(true)
170
- scenario.should_receive(:accept_hook?).with(meat).and_return(false)
171
-
172
- @rb.hooks_for(:before, scenario).should == [fish]
173
- end
174
-
175
- it "should find around hooks" do
176
- a = @dsl.Around do |scenario, block|
177
- end
178
-
179
- b = @dsl.Around('@tag') do |scenario, block|
180
- end
181
-
182
- scenario = mock('Scenario')
183
- scenario.should_receive(:accept_hook?).with(a).and_return(true)
184
- scenario.should_receive(:accept_hook?).with(b).and_return(false)
185
-
186
- @rb.hooks_for(:around, scenario).should == [a]
187
- end
188
- end
189
-
190
- describe StepMother, "step argument transformations" do
191
- before do
192
- @dsl = Object.new
193
- @dsl.extend(RbSupport::RbDsl)
194
-
195
- @step_mother = StepMother.new
196
-
197
- @rb = @step_mother.load_programming_language('rb')
198
- end
199
-
200
- describe "without capture groups" do
201
- it "complains when registering with a with no transform block" do
202
- lambda do
203
- @dsl.Transform('^abc$')
204
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
205
- end
206
-
207
- it "complains when registering with a zero-arg transform block" do
208
- lambda do
209
- @dsl.Transform('^abc$') {42}
210
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
211
- end
212
-
213
- it "complains when registering with a splat-arg transform block" do
214
- lambda do
215
- @dsl.Transform('^abc$') {|*splat| 42 }
216
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
217
- end
218
-
219
- it "complains when transforming with an arity mismatch" do
220
- lambda do
221
- @dsl.Transform('^abc$') {|one, two| 42 }
222
- @rb.execute_transforms(['abc'])
223
- end.should raise_error(Cucumber::ArityMismatchError)
224
- end
225
-
226
- it "allows registering a regexp pattern that yields the step_arg matched" do
227
- @dsl.Transform(/^ab*c$/) {|arg| 42}
228
- @rb.execute_transforms(['ab']).should == ['ab']
229
- @rb.execute_transforms(['ac']).should == [42]
230
- @rb.execute_transforms(['abc']).should == [42]
231
- @rb.execute_transforms(['abbc']).should == [42]
232
- end
233
- end
234
-
235
- describe "with capture groups" do
236
- it "complains when registering with a with no transform block" do
237
- lambda do
238
- @dsl.Transform('^a(.)c$')
239
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
240
- end
241
-
242
- it "complains when registering with a zero-arg transform block" do
243
- lambda do
244
- @dsl.Transform('^a(.)c$') { 42 }
245
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
246
- end
247
-
248
- it "complains when registering with a splat-arg transform block" do
249
- lambda do
250
- @dsl.Transform('^a(.)c$') {|*splat| 42 }
251
- end.should raise_error(Cucumber::RbSupport::RbTransform::MissingProc)
252
- end
253
-
254
- it "complains when transforming with an arity mismatch" do
255
- lambda do
256
- @dsl.Transform('^a(.)c$') {|one, two| 42 }
257
- @rb.execute_transforms(['abc'])
258
- end.should raise_error(Cucumber::ArityMismatchError)
259
- end
260
-
261
- it "allows registering a regexp pattern that yields capture groups" do
262
- @dsl.Transform(/^shape: (.+), color: (.+)$/) do |shape, color|
263
- {shape.to_sym => color.to_sym}
264
- end
265
- @rb.execute_transforms(['shape: circle, color: blue']).should == [{:circle => :blue}]
266
- @rb.execute_transforms(['shape: square, color: red']).should == [{:square => :red}]
267
- @rb.execute_transforms(['not shape: square, not color: red']).should == ['not shape: square, not color: red']
268
- end
269
- end
270
-
271
- it "allows registering a string pattern" do
272
- @dsl.Transform('^ab*c$') {|arg| 42}
273
- @rb.execute_transforms(['ab']).should == ['ab']
274
- @rb.execute_transforms(['ac']).should == [42]
275
- @rb.execute_transforms(['abc']).should == [42]
276
- @rb.execute_transforms(['abbc']).should == [42]
277
- end
278
-
279
- it "gives match priority to transforms defined last" do
280
- @dsl.Transform(/^transform_me$/) {|arg| :foo }
281
- @dsl.Transform(/^transform_me$/) {|arg| :bar }
282
- @dsl.Transform(/^transform_me$/) {|arg| :baz }
283
- @rb.execute_transforms(['transform_me']).should == [:baz]
284
- end
285
-
286
- it "allows registering a transform which returns nil" do
287
- @dsl.Transform('^ac$') {|arg| nil}
288
- @rb.execute_transforms(['ab']).should == ['ab']
289
- @rb.execute_transforms(['ac']).should == [nil]
290
- end
291
- end
292
-
293
- end
294
-
295
- module ModuleOne
296
- end
297
-
298
- module ModuleTwo
299
- end
300
-
301
- class ClassOne
302
- end