kosmas58-cucumber 0.2.0.1 → 0.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History.txt +32 -1
  2. data/Manifest.txt +4 -11
  3. data/examples/dos_line_endings/features/dos_line_endings.feature +9 -9
  4. data/examples/pure_java/README.textile +5 -0
  5. data/examples/self_test/features/tons_of_cukes.feature +52 -0
  6. data/examples/sinatra/features/support/env.rb +6 -2
  7. data/examples/tickets/features/248.feature +11 -0
  8. data/examples/tickets/features/step_definitons/248_steps.rb +15 -0
  9. data/features/cucumber_cli.feature +1 -1
  10. data/features/custom_formatter.feature +2 -2
  11. data/features/usage.feature +108 -0
  12. data/gem_tasks/features.rake +18 -6
  13. data/lib/autotest/cucumber_mixin.rb +1 -1
  14. data/lib/cucumber/ast/feature.rb +1 -1
  15. data/lib/cucumber/ast/features.rb +6 -0
  16. data/lib/cucumber/ast/step.rb +4 -0
  17. data/lib/cucumber/ast/step_invocation.rb +10 -2
  18. data/lib/cucumber/ast/table.rb +4 -0
  19. data/lib/cucumber/cli/configuration.rb +11 -14
  20. data/lib/cucumber/cli/main.rb +14 -21
  21. data/lib/cucumber/core_ext/exception.rb +1 -1
  22. data/lib/cucumber/formatter.rb +1 -1
  23. data/lib/cucumber/formatter/html.rb +47 -8
  24. data/lib/cucumber/formatter/pretty.rb +1 -2
  25. data/lib/cucumber/formatter/rerun.rb +8 -0
  26. data/lib/cucumber/formatter/usage.rb +69 -0
  27. data/lib/cucumber/languages.yml +7 -2
  28. data/lib/cucumber/rails/world.rb +22 -21
  29. data/lib/cucumber/step_definition.rb +65 -54
  30. data/lib/cucumber/step_match.rb +10 -2
  31. data/lib/cucumber/step_mother.rb +4 -10
  32. data/lib/cucumber/version.rb +1 -1
  33. data/rails_generators/cucumber/templates/env.rb +2 -0
  34. data/rails_generators/feature/templates/steps.erb +1 -1
  35. data/spec/cucumber/ast/feature_spec.rb +2 -1
  36. data/spec/cucumber/cli/configuration_spec.rb +18 -6
  37. data/spec/cucumber/cli/main_spec.rb +1 -14
  38. data/spec/cucumber/parser/feature_parser_spec.rb +15 -15
  39. data/spec/cucumber/step_definition_spec.rb +21 -9
  40. data/spec/cucumber/step_mother_spec.rb +17 -1
  41. metadata +8 -13
  42. data/examples/jbehave/README.textile +0 -20
  43. data/examples/jbehave/features/support/env.rb +0 -7
  44. data/examples/jbehave/features/trading.feature +0 -28
  45. data/examples/jbehave/pom.xml +0 -53
  46. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/converters/TraderConverter.java +0 -32
  47. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Stock.java +0 -42
  48. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Trader.java +0 -29
  49. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/persistence/TraderPersister.java +0 -22
  50. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/scenarios/TraderSteps.java +0 -70
  51. data/gem_tasks/jar.rake +0 -67
  52. data/lib/cucumber/jbehave.rb +0 -97
@@ -3,6 +3,50 @@ require 'cucumber/core_ext/string'
3
3
  require 'cucumber/core_ext/proc'
4
4
 
5
5
  module Cucumber
6
+ module StepDefinitionMethods
7
+ def step_match(name_to_match, name_to_report)
8
+ if(match = name_to_match.match(regexp))
9
+ StepMatch.new(self, name_to_match, name_to_report, match.captures)
10
+ else
11
+ nil
12
+ end
13
+ end
14
+
15
+ # Formats the matched arguments of the associated Step. This method
16
+ # is usually called from visitors, which render output.
17
+ #
18
+ # The +format+ can either be a String or a Proc.
19
+ #
20
+ # If it is a String it should be a format string according to
21
+ # <tt>Kernel#sprinf</tt>, for example:
22
+ #
23
+ # '<span class="param">%s</span></tt>'
24
+ #
25
+ # If it is a Proc, it should take one argument and return the formatted
26
+ # argument, for example:
27
+ #
28
+ # lambda { |param| "[#{param}]" }
29
+ #
30
+ def format_args(step_name, format)
31
+ step_name.gzub(regexp, format)
32
+ end
33
+
34
+ def match(step_name)
35
+ case step_name
36
+ when String then regexp.match(step_name)
37
+ when Regexp then regexp == step_name
38
+ end
39
+ end
40
+
41
+ def backtrace_line
42
+ "#{file_colon_line}:in `#{regexp.inspect}'"
43
+ end
44
+
45
+ def text_length
46
+ regexp.inspect.jlength
47
+ end
48
+ end
49
+
6
50
  # A Step Definition holds a Regexp and a Proc, and is created
7
51
  # by calling <tt>Given</tt>, <tt>When</tt> or <tt>Then</tt>
8
52
  # in the <tt>step_definitions</tt> ruby files - for example:
@@ -14,7 +58,22 @@ module Cucumber
14
58
  class StepDefinition
15
59
  def self.snippet_text(step_keyword, step_name)
16
60
  escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
17
- "#{step_keyword} /^#{escaped}$/ do\n pending\nend"
61
+ param_pattern = /"([^\"]*)"/
62
+
63
+ match = escaped.match(param_pattern)
64
+ if match
65
+ n = 0
66
+ block_args = match.captures.map do |a|
67
+ n += 1
68
+ "arg#{n}"
69
+ end
70
+ block_arg_string = " |#{block_args.join(", ")}|"
71
+ else
72
+ block_arg_string = ""
73
+ end
74
+
75
+ escaped = escaped.gsub(param_pattern, '"([^\\"]*)"')
76
+ "#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n pending\nend"
18
77
  end
19
78
 
20
79
  class MissingProc < StandardError
@@ -23,7 +82,7 @@ module Cucumber
23
82
  end
24
83
  end
25
84
 
26
- attr_reader :regexp
85
+ include StepDefinitionMethods
27
86
 
28
87
  def initialize(pattern, &proc)
29
88
  raise MissingProc if proc.nil?
@@ -34,70 +93,22 @@ module Cucumber
34
93
  @regexp, @proc = pattern, proc
35
94
  end
36
95
 
37
- def step_match(name_to_match, name_to_report)
38
- if(match = name_to_match.match(@regexp))
39
- StepMatch.new(self, name_to_match, name_to_report, match.captures)
40
- else
41
- nil
42
- end
96
+ def regexp
97
+ @regexp
43
98
  end
44
99
 
45
- def invoke(world, args, step_name)
100
+ def invoke(world, args)
46
101
  args = args.map{|arg| Ast::PyString === arg ? arg.to_s : arg}
47
102
  begin
48
- world.cucumber_instance_exec(true, @regexp.inspect, *args, &@proc)
103
+ world.cucumber_instance_exec(true, regexp.inspect, *args, &@proc)
49
104
  rescue Cucumber::ArityMismatchError => e
50
105
  e.backtrace.unshift(self.backtrace_line)
51
106
  raise e
52
107
  end
53
108
  end
54
109
 
55
- #:stopdoc:
56
-
57
- def match(step_name)
58
- case step_name
59
- when String then @regexp.match(step_name)
60
- when Regexp then @regexp == step_name
61
- end
62
- end
63
-
64
- # Formats the matched arguments of the associated Step. This method
65
- # is usually called from visitors, which render output.
66
- #
67
- # The +format+ can either be a String or a Proc.
68
- #
69
- # If it is a String it should be a format string according to
70
- # <tt>Kernel#sprinf</tt>, for example:
71
- #
72
- # '<span class="param">%s</span></tt>'
73
- #
74
- # If it is a Proc, it should take one argument and return the formatted
75
- # argument, for example:
76
- #
77
- # lambda { |param| "[#{param}]" }
78
- #
79
- def format_args(step_name, format)
80
- step_name.gzub(@regexp, format)
81
- end
82
-
83
- def matched_args(step_name)
84
- step_name.match(@regexp).captures
85
- end
86
-
87
- def backtrace_line
88
- "#{file_colon_line}:in `#{@regexp.inspect}'"
89
- end
90
-
91
110
  def file_colon_line
92
111
  @proc.file_colon_line
93
112
  end
94
-
95
- def text_length
96
- @regexp.inspect.jlength
97
- end
98
-
99
- def to_s(indent = 0)
100
- @regexp.inspect + (' # ').indent(indent) + file_colon_line
101
- end
102
113
  end
103
114
  end
@@ -10,10 +10,10 @@ module Cucumber
10
10
  def invoke(world, multiline_arg)
11
11
  all_args = @args.dup
12
12
  all_args << multiline_arg if multiline_arg
13
- @step_definition.invoke(world, all_args, @step_name)
13
+ @step_definition.invoke(world, all_args)
14
14
  end
15
15
 
16
- def format_args(format)
16
+ def format_args(format = lambda{|a| a})
17
17
  @formatted_step_name || @step_definition.format_args(@step_name, format)
18
18
  end
19
19
 
@@ -24,6 +24,10 @@ module Cucumber
24
24
  def backtrace_line
25
25
  @step_definition.backtrace_line
26
26
  end
27
+
28
+ def text_length
29
+ @step_definition.text_length
30
+ end
27
31
  end
28
32
 
29
33
  class NoStepMatch
@@ -45,5 +49,9 @@ module Cucumber
45
49
  def backtrace_line
46
50
  @step.backtrace_line
47
51
  end
52
+
53
+ def text_length
54
+ @step.text_length
55
+ end
48
56
  end
49
57
  end
@@ -26,10 +26,11 @@ module Cucumber
26
26
 
27
27
  # Raised when a step matches 2 or more StepDefinition
28
28
  class Ambiguous < StandardError
29
- def initialize(step_name, step_definitions)
29
+ def initialize(step_name, step_definitions, used_guess)
30
30
  message = "Ambiguous match of \"#{step_name}\":\n\n"
31
31
  message << step_definitions.map{|sd| sd.backtrace_line}.join("\n")
32
32
  message << "\n\n"
33
+ message << "You can run again with --guess to make Cucumber be more smart about it\n" unless used_guess
33
34
  super(message)
34
35
  end
35
36
  end
@@ -101,7 +102,7 @@ module Cucumber
101
102
  end
102
103
 
103
104
  def After(&proc)
104
- (@after_procs ||= []) << proc
105
+ (@after_procs ||= []).unshift(proc)
105
106
  end
106
107
 
107
108
  # Registers a World proc. You can call this method as many times as you
@@ -118,7 +119,7 @@ module Cucumber
118
119
  matches = step_definitions.map { |d| d.step_match(step_name, formatted_step_name) }.compact
119
120
  raise Undefined.new(step_name) if matches.empty?
120
121
  matches = best_matches(step_name, matches) if matches.size > 1 && options[:guess]
121
- raise Ambiguous.new(step_name, matches) if matches.size > 1
122
+ raise Ambiguous.new(step_name, matches, options[:guess]) if matches.size > 1
122
123
  matches[0]
123
124
  end
124
125
 
@@ -141,13 +142,6 @@ module Cucumber
141
142
  def snippet_text(step_keyword, step_name)
142
143
  @snippet_generator.snippet_text(step_keyword, step_name)
143
144
  end
144
-
145
- def print_step_definitions(out)
146
- step_definitions.each do |step_definition|
147
- indent = max_step_definition_length - step_definition.text_length
148
- out.puts(step_definition.to_s(indent))
149
- end
150
- end
151
145
 
152
146
  def before_and_after(scenario, skip=false)
153
147
  unless current_world || skip
@@ -2,7 +2,7 @@ module Cucumber #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 2
6
6
  PATCH = 1 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
@@ -4,6 +4,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4
4
  require 'cucumber/rails/world'
5
5
  require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
6
6
  Cucumber::Rails.use_transactional_fixtures
7
+ Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
8
+ # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
7
9
 
8
10
  require 'webrat'
9
11
 
@@ -10,7 +10,7 @@ When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
10
10
  end
11
11
 
12
12
  Then /^I should see the following <%= plural_name %>:$/ do |<%= plural_name %>|
13
- <%= plural_name %>.raw[1..-1].each_with_index do |row, i|
13
+ <%= plural_name %>.rows.each_with_index do |row, i|
14
14
  row.each_with_index do |cell, j|
15
15
  response.should have_selector("table > tr:nth-child(#{i+2}) > td:nth-child(#{j+1})") { |td|
16
16
  td.inner_text.should == cell
@@ -9,7 +9,8 @@ module Cucumber
9
9
  it "should convert to sexp" do
10
10
  feature = create_feature(Object.new)
11
11
  feature.to_sexp.should ==
12
- [:feature,
12
+ [:feature,
13
+ "features/pretty_printing.feature",
13
14
  "Pretty printing",
14
15
  [:comment, "# My feature comment\n"],
15
16
  [:tag, "one"],
@@ -18,7 +18,7 @@ module Cli
18
18
  it "should require files in support paths first" do
19
19
  File.stub!(:directory?).and_return(true)
20
20
  Dir.stub!(:[]).and_return(["/features/step_definitions/foo.rb","/features/support/bar.rb"])
21
-
21
+
22
22
  config = Configuration.new(StringIO.new)
23
23
  config.parse!(%w{--require /features})
24
24
 
@@ -31,7 +31,7 @@ module Cli
31
31
  it "should require env.rb files first" do
32
32
  File.stub!(:directory?).and_return(true)
33
33
  Dir.stub!(:[]).and_return(["/features/support/a_file.rb","/features/support/env.rb"])
34
-
34
+
35
35
  config = Configuration.new(StringIO.new)
36
36
  config.parse!(%w{--require /features})
37
37
 
@@ -40,7 +40,19 @@ module Cli
40
40
  "/features/support/a_file.rb"
41
41
  ]
42
42
  end
43
-
43
+
44
+ it "should not require env.rb files when --dry-run" do
45
+ File.stub!(:directory?).and_return(true)
46
+ Dir.stub!(:[]).and_return(["/features/support/a_file.rb","/features/support/env.rb"])
47
+
48
+ config = Configuration.new(StringIO.new)
49
+ config.parse!(%w{--require /features --dry-run})
50
+
51
+ config.files_to_require.should == [
52
+ "/features/support/a_file.rb"
53
+ ]
54
+ end
55
+
44
56
  it "should expand args from YAML file" do
45
57
  given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
46
58
 
@@ -101,11 +113,11 @@ END_OF_MESSAGE
101
113
  config = Configuration.new(StringIO.new, error = StringIO.new)
102
114
  config.parse!(%w{--profile i_do_not_exist})
103
115
 
104
- error.string.should match(/cucumber.yml was not found. Please refer to cucumber's documentaion on defining profiles in cucumber.yml./)
116
+ error.string.should match(/cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml./)
105
117
  end
106
118
 
107
119
  it "should provide a helpful error message when cucumber.yml is blank or malformed" do
108
- expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentaion on correct profile usage./
120
+ expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
109
121
 
110
122
  ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
111
123
  given_cucumber_yml_defined_as(bad_input)
@@ -118,7 +130,7 @@ END_OF_MESSAGE
118
130
  end
119
131
 
120
132
  it "should procide a helpful error message when the YAML can not be parsed" do
121
- expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentaion on correct profile usage./
133
+ expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./
122
134
 
123
135
  given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
124
136
  YAML.should_receive(:load).and_raise Exception
@@ -1,5 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'spec/expectations/differs/default'
3
2
  require 'yaml'
4
3
  require 'spec/expectations/differs/default'
5
4
 
@@ -11,18 +10,6 @@ module Cli
11
10
  Kernel.stub!(:exit).and_return(nil)
12
11
  end
13
12
 
14
- it "should print step definitions" do
15
- step_mother = Object.new.extend(StepMother)
16
- step_mother.Given(/Bonjour/) {}
17
- step_mother.Given(/Monde/) {}
18
- @cli = Main.new(%w{-S}, @out)
19
- @cli.execute!(step_mother)
20
- @out.string.should == %{
21
- /Bonjour/ # spec/cucumber/cli/main_spec.rb:16
22
- /Monde/ # spec/cucumber/cli/main_spec.rb:17
23
- }.lstrip
24
- end
25
-
26
13
  describe "verbose mode" do
27
14
 
28
15
  before(:each) do
@@ -55,7 +42,7 @@ module Cli
55
42
  describe "diffing" do
56
43
 
57
44
  before :each do
58
- @configuration = mock('Configuration', :null_object => true, :print_step_definitions? => nil)
45
+ @configuration = mock('Configuration', :null_object => true)
59
46
  Configuration.should_receive(:new).and_return(@configuration)
60
47
 
61
48
  @step_mother = mock('StepMother', :null_object => true)
@@ -33,7 +33,7 @@ with blurb
33
33
  parse(%{# My comment
34
34
  Feature: hi
35
35
  }).to_sexp.should ==
36
- [:feature, "Feature: hi\n",
36
+ [:feature, nil, "Feature: hi\n",
37
37
  [:comment, "# My comment\n"]]
38
38
  end
39
39
 
@@ -45,7 +45,7 @@ Feature: hi
45
45
  # When bar
46
46
  Then baz
47
47
  }).to_sexp.should ==
48
- [:feature, "Feature: Hi",
48
+ [:feature, nil, "Feature: Hi",
49
49
  [:scenario, 2, "Scenario:", "Hello",
50
50
  [:step, 3, "Given", "foo"],
51
51
  [:comment, "# When bar\n"],
@@ -59,18 +59,18 @@ Feature: hi
59
59
  # World
60
60
  Feature: hi
61
61
  }).to_sexp.should ==
62
- [:feature, "Feature: hi\n",
62
+ [:feature, nil, "Feature: hi\n",
63
63
  [:comment, "# Hello\n# World\n"]]
64
64
  end
65
65
 
66
66
  it "should parse a file with no comments" do
67
67
  parse("Feature: hi\n").to_sexp.should ==
68
- [:feature, "Feature: hi\n"]
68
+ [:feature, nil, "Feature: hi\n"]
69
69
  end
70
70
 
71
71
  it "should parse a file with only a multiline comment with newlines" do
72
72
  parse("# Hello\n\n# World\n").to_sexp.should ==
73
- [:feature, "",
73
+ [:feature, nil, "",
74
74
  [:comment, "# Hello\n\n# World\n"]]
75
75
  end
76
76
  end
@@ -78,7 +78,7 @@ Feature: hi
78
78
  describe "Tags" do
79
79
  it "should parse a file with tags on a feature" do
80
80
  parse("# My comment\n@hello @world Feature: hi\n").to_sexp.should ==
81
- [:feature, "Feature: hi\n",
81
+ [:feature, nil, "Feature: hi\n",
82
82
  [:comment, "# My comment\n"],
83
83
  [:tag, "hello"],
84
84
  [:tag, "world"]]
@@ -96,7 +96,7 @@ Feature: hi
96
96
  @st3
97
97
  @st4 @ST5 @#^%&ST6**!
98
98
  Scenario: Second}).to_sexp.should ==
99
- [:feature, "Feature: hi",
99
+ [:feature, nil, "Feature: hi",
100
100
  [:comment, "# FC\n "],
101
101
  [:tag, "ft"],
102
102
  [:scenario, 6, 'Scenario:', 'First',
@@ -111,7 +111,7 @@ Feature: hi
111
111
  describe "Background" do
112
112
  it "should have steps" do
113
113
  parse("Feature: Hi\nBackground:\nGiven I am a step\n").to_sexp.should ==
114
- [:feature, "Feature: Hi",
114
+ [:feature, nil, "Feature: Hi",
115
115
  [:background, 2, "Background:",
116
116
  [:step, 3, "Given", "I am a step"]]]
117
117
  end
@@ -120,7 +120,7 @@ Feature: hi
120
120
  describe "Scenarios" do
121
121
  it "can be empty" do
122
122
  parse("Feature: Hi\n\nScenario: Hello\n").to_sexp.should ==
123
- [:feature, "Feature: Hi",
123
+ [:feature, nil, "Feature: Hi",
124
124
  [:scenario, 3, "Scenario:", "Hello"]]
125
125
  end
126
126
 
@@ -134,7 +134,7 @@ Scenario: bar
134
134
 
135
135
  it "should have steps" do
136
136
  parse("Feature: Hi\nScenario: Hello\nGiven I am a step\n").to_sexp.should ==
137
- [:feature, "Feature: Hi",
137
+ [:feature, nil, "Feature: Hi",
138
138
  [:scenario, 2, "Scenario:", "Hello",
139
139
  [:step_invocation, 3, "Given", "I am a step"]]]
140
140
  end
@@ -145,7 +145,7 @@ Scenario: Hello
145
145
  Given I have a table
146
146
  |a|b|
147
147
  }).to_sexp.should ==
148
- [:feature, "Feature: Hi",
148
+ [:feature, nil, "Feature: Hi",
149
149
  [:scenario, 2, "Scenario:", "Hello",
150
150
  [:step_invocation, 3, "Given", "I have a table",
151
151
  [:table,
@@ -166,7 +166,7 @@ Given I have a string
166
166
  """
167
167
 
168
168
  }).to_sexp.should ==
169
- [:feature, "Feature: Hi",
169
+ [:feature, nil, "Feature: Hi",
170
170
  [:scenario, 2, "Scenario:", "Hello",
171
171
  [:step_invocation, 3, "Given", "I have a string",
172
172
  [:py_string, "hello\nworld"]]]]
@@ -182,7 +182,7 @@ Examples:
182
182
  |what|
183
183
  |green|
184
184
  }).to_sexp.should ==
185
- [:feature, "Feature: Hi",
185
+ [:feature, nil, "Feature: Hi",
186
186
  [:scenario_outline, "Scenario Outline:", "Hello",
187
187
  [:step, 3, "Given", "a <what> cucumber"],
188
188
  [:examples, "Examples:", "",
@@ -203,7 +203,7 @@ Examples:
203
203
  |a|b|
204
204
  |c|d|
205
205
  }).to_sexp.should ==
206
- [:feature, "Feature: Hi",
206
+ [:feature, nil, "Feature: Hi",
207
207
  [:scenario_outline, "Scenario Outline:", "Hello",
208
208
  [:step, 4, "Given", "I have a table",
209
209
  [:table,
@@ -233,7 +233,7 @@ Examples:
233
233
  |5|6|
234
234
 
235
235
  ").to_sexp.should ==
236
- [:feature, "Feature: Hi",
236
+ [:feature, nil, "Feature: Hi",
237
237
  [:scenario_outline, "Scenario Outline:", "Hello",
238
238
  [:step, 5, "Given", "I have a table",
239
239
  [:table,