aslakhellesoy-cucumber 0.3.9.3 → 0.3.9.4

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.
@@ -113,11 +113,11 @@ Feature: Cucumber command line
113
113
  Then the multiline string should be # features/background/multiline_args_background.feature:17
114
114
  Then the multiline string should be # features/background/multiline_args_background.feature:27
115
115
  /^passing$/ # features/step_definitions/sample_steps.rb:5
116
- Given passing # features/sample.feature:10
116
+ Given passing # features/sample.feature:12
117
117
  /^failing expectation$/ # features/step_definitions/sample_steps.rb:62
118
118
  Given failing expectation # features/failing_expectation.feature:4
119
119
  /^failing$/ # features/step_definitions/sample_steps.rb:8
120
- Given failing # features/sample.feature:16
120
+ Given failing # features/sample.feature:18
121
121
  (::) UNUSED (::)
122
122
  /^unused$/ # features/step_definitions/sample_steps.rb:66
123
123
  /^another unused$/ # features/step_definitions/sample_steps.rb:69
@@ -23,7 +23,7 @@ module Cucumber
23
23
  end
24
24
 
25
25
  def accept(visitor)
26
- visitor.visit_comment(@comment)
26
+ visitor.visit_comment(@comment) unless @comment.empty?
27
27
  visitor.visit_background_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
28
28
  visitor.step_mother.before(hook_context)
29
29
  visitor.visit_steps(@step_invocations)
@@ -12,6 +12,10 @@ module Cucumber
12
12
  @value = value
13
13
  end
14
14
 
15
+ def empty?
16
+ @value.nil? || @value == ""
17
+ end
18
+
15
19
  def accept(visitor)
16
20
  @value.split("\n").each do |line|
17
21
  visitor.visit_comment_line(line.strip)
@@ -4,6 +4,7 @@ module Cucumber
4
4
  class Feature
5
5
  attr_accessor :file
6
6
  attr_writer :features
7
+ attr_reader :name
7
8
 
8
9
  def initialize(background, comment, tags, name, feature_elements)
9
10
  @background, @comment, @tags, @name, @feature_elements = background, comment, tags, name, feature_elements
@@ -15,7 +16,7 @@ module Cucumber
15
16
  end
16
17
 
17
18
  def accept(visitor)
18
- visitor.visit_comment(@comment)
19
+ visitor.visit_comment(@comment) unless @comment.empty?
19
20
  visitor.visit_tags(@tags)
20
21
  visitor.visit_feature_name(@name)
21
22
  visitor.visit_background(@background) if @background
@@ -70,7 +70,7 @@ module Cucumber
70
70
  visitor.step_mother.before_and_after(self) do
71
71
  @step_invocations.each do |step_invocation|
72
72
  step_invocation.invoke(visitor.step_mother, visitor.options)
73
- @exception ||= step_invocation.exception
73
+ @exception ||= step_invocation.reported_exception
74
74
  end
75
75
 
76
76
  @cells.each do |cell|
@@ -89,7 +89,7 @@ module Cucumber
89
89
  @table.visit_scenario_name(visitor, self)
90
90
  @step_invocations.each do |step_invocation|
91
91
  step_invocation.invoke(visitor.step_mother, visitor.options)
92
- @exception ||= step_invocation.exception
92
+ @exception ||= step_invocation.reported_exception
93
93
  step_invocation.visit_step_result(visitor)
94
94
  end
95
95
  end
@@ -21,7 +21,7 @@ module Cucumber
21
21
  end
22
22
 
23
23
  def accept(visitor)
24
- visitor.visit_comment(@comment)
24
+ visitor.visit_comment(@comment) unless @comment.empty?
25
25
  visitor.visit_tags(@tags)
26
26
  visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
27
27
 
@@ -3,6 +3,14 @@ module Cucumber
3
3
  class ScenarioOutline
4
4
  include FeatureElement
5
5
 
6
+ module ExamplesArray
7
+ def accept(visitor)
8
+ each do |examples|
9
+ visitor.visit_examples(examples)
10
+ end
11
+ end
12
+ end
13
+
6
14
  # The +example_sections+ argument must be an Array where each element is another array representing
7
15
  # an Examples section. This array has 3 elements:
8
16
  #
@@ -23,20 +31,19 @@ module Cucumber
23
31
  examples_table = OutlineTable.new(examples_matrix, self)
24
32
  Examples.new(examples_line, examples_keyword, examples_name, examples_table)
25
33
  end
34
+ @examples_array.extend(ExamplesArray)
26
35
 
27
36
  @background.feature_elements << self if @background
28
37
  end
29
38
 
30
39
  def accept(visitor)
31
- visitor.visit_comment(@comment)
40
+ visitor.visit_comment(@comment) unless @comment.empty?
32
41
  visitor.visit_tags(@tags)
33
42
  visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
34
43
  visitor.visit_steps(@steps)
35
44
 
36
45
  skip_invoke! if @background && @background.failed?
37
- @examples_array.each do |examples|
38
- visitor.visit_examples(examples)
39
- end
46
+ visitor.visit_examples_array(@examples_array) unless @examples_array.empty?
40
47
  end
41
48
 
42
49
  def skip_invoke!
@@ -2,7 +2,7 @@ module Cucumber
2
2
  module Ast
3
3
  class StepInvocation
4
4
  attr_writer :step_collection, :background
5
- attr_reader :name, :matched_cells, :status
5
+ attr_reader :name, :matched_cells, :status, :reported_exception
6
6
  attr_accessor :exception
7
7
 
8
8
  def initialize(step, name, multiline_arg, matched_cells)
@@ -24,12 +24,12 @@ module Cucumber
24
24
  end
25
25
 
26
26
  def visit_step_result(visitor)
27
- visitor.visit_step_result(keyword, @step_match, @multiline_arg, @status, @exception, source_indent, @background)
27
+ visitor.visit_step_result(keyword, @step_match, @multiline_arg, @status, @reported_exception, source_indent, @background)
28
28
  end
29
29
 
30
30
  def invoke(step_mother, options)
31
31
  find_step_match!(step_mother)
32
- unless @skip_invoke || options[:dry_run] || exception || @step_collection.exception
32
+ unless @skip_invoke || options[:dry_run] || @exception || @step_collection.exception
33
33
  @skip_invoke = true
34
34
  begin
35
35
  step_mother.current_world.__cucumber_current_step = self if step_mother.current_world # Nil in Pure Java
@@ -37,13 +37,13 @@ module Cucumber
37
37
  step_mother.after_step
38
38
  status!(:passed)
39
39
  rescue Pending => e
40
- failed(e, false)
40
+ failed(options, e, false)
41
41
  status!(:pending)
42
42
  rescue Undefined => e
43
- failed(e, false)
43
+ failed(options, e, false)
44
44
  status!(:undefined)
45
45
  rescue Exception => e
46
- failed(e, false)
46
+ failed(options, e, false)
47
47
  status!(:failed)
48
48
  end
49
49
  end
@@ -54,21 +54,26 @@ module Cucumber
54
54
  begin
55
55
  @step_match = step_mother.step_match(@name)
56
56
  rescue Undefined => e
57
- failed(e, true)
57
+ failed(step_mother.options, e, true)
58
58
  status!(:undefined)
59
59
  @step_match = NoStepMatch.new(@step, @name)
60
60
  rescue Ambiguous => e
61
- failed(e, false)
61
+ failed(step_mother.options, e, false)
62
62
  status!(:failed)
63
63
  @step_match = NoStepMatch.new(@step, @name)
64
64
  end
65
65
  step_mother.step_visited(self)
66
66
  end
67
67
 
68
- def failed(exception, clear_backtrace)
69
- @exception = exception
70
- @exception.set_backtrace([]) if clear_backtrace
71
- @exception.backtrace << @step.backtrace_line unless @step.backtrace_line.nil?
68
+ def failed(options, e, clear_backtrace)
69
+ e.set_backtrace([]) if clear_backtrace
70
+ e.backtrace << @step.backtrace_line unless @step.backtrace_line.nil?
71
+ @exception = e
72
+ if(options[:strict] || !(Undefined === e) || e.nested?)
73
+ @reported_exception = e
74
+ else
75
+ @reported_exception = nil
76
+ end
72
77
  end
73
78
 
74
79
  def status!(status)
@@ -52,6 +52,10 @@ module Cucumber
52
52
  def visit_background_name(keyword, name, file_colon_line, source_indent)
53
53
  end
54
54
 
55
+ def visit_examples_array(examples_array)
56
+ examples_array.accept(self)
57
+ end
58
+
55
59
  def visit_examples(examples)
56
60
  examples.accept(self)
57
61
  end
@@ -66,9 +66,7 @@ module Cucumber
66
66
  end
67
67
 
68
68
  def print_exception(e, status, indent)
69
- if @options[:strict] || !(Undefined === e) || e.nested?
70
- @io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
71
- end
69
+ @io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
72
70
  end
73
71
 
74
72
  def print_snippets(options)
@@ -15,6 +15,7 @@ module Cucumber
15
15
 
16
16
  def initialize(step_mother, io, options)
17
17
  super(step_mother)
18
+ @options = options
18
19
  @builder = Builder::XmlMarkup.new(:target => io, :indent => 2)
19
20
  end
20
21
 
@@ -42,7 +43,18 @@ module Cucumber
42
43
  end
43
44
  end
44
45
 
46
+ def visit_comment(comment)
47
+ @builder.pre(:class => 'comment') do
48
+ super
49
+ end
50
+ end
51
+
52
+ def visit_comment_line(comment_line)
53
+ @builder.text!(comment_line.strip + "\n")
54
+ end
55
+
45
56
  def visit_feature(feature)
57
+ @exceptions = []
46
58
  @builder.div(:class => 'feature') do
47
59
  super
48
60
  end
@@ -54,7 +66,9 @@ module Cucumber
54
66
 
55
67
  def visit_feature_name(name)
56
68
  lines = name.split(/\r?\n/)
57
- @builder.h2(lines[0])
69
+ @builder.h2 do |h2|
70
+ @builder.span(lines[0], :class => 'val')
71
+ end
58
72
  @builder.p do
59
73
  lines[1..-1].each do |line|
60
74
  @builder.text!(line.strip)
@@ -65,17 +79,26 @@ module Cucumber
65
79
 
66
80
  def visit_background(background)
67
81
  @builder.div(:class => 'background') do
82
+ @in_background = true
68
83
  super
84
+ @in_background = nil
69
85
  end
70
86
  end
71
87
 
72
88
  def visit_background_name(keyword, name, file_colon_line, source_indent)
73
89
  @listing_background = true
74
- @builder.h3("#{keyword} #{name}")
90
+ @builder.h3 do |h3|
91
+ @builder.span(keyword, :class => 'keyword')
92
+ @builder.span(name, :class => 'val')
93
+ end
75
94
  end
76
95
 
77
96
  def visit_feature_element(feature_element)
78
- @builder.div(:class => 'scenario') do
97
+ css_class = {
98
+ Ast::Scenario => 'scenario',
99
+ Ast::ScenarioOutline => 'scenario outline'
100
+ }[feature_element.class]
101
+ @builder.div(:class => css_class) do
79
102
  super
80
103
  end
81
104
  @open_step_list = true
@@ -83,7 +106,10 @@ module Cucumber
83
106
 
84
107
  def visit_scenario_name(keyword, name, file_colon_line, source_indent)
85
108
  @listing_background = false
86
- @builder.h3("#{keyword} #{name}")
109
+ @builder.h3 do
110
+ @builder.span(keyword, :class => 'keyword')
111
+ @builder.span(name, :class => 'val')
112
+ end
87
113
  end
88
114
 
89
115
  def visit_outline_table(outline_table)
@@ -94,6 +120,12 @@ module Cucumber
94
120
  @outline_row = nil
95
121
  end
96
122
 
123
+ def visit_examples(examples)
124
+ @builder.div(:class => 'examples') do
125
+ super(examples)
126
+ end
127
+ end
128
+
97
129
  def visit_examples_name(keyword, name)
98
130
  @builder.h4("#{keyword} #{name}")
99
131
  end
@@ -110,6 +142,11 @@ module Cucumber
110
142
  end
111
143
 
112
144
  def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
145
+ if exception
146
+ return if @exceptions.index(exception)
147
+ @exceptions << exception
148
+ end
149
+ return if status != :failed && @in_background ^ background
113
150
  @status = status
114
151
  @builder.li(:id => @step_id, :class => "step #{status}") do
115
152
  super(keyword, step_match, multiline_arg, status, exception, source_indent, background)
@@ -143,7 +180,7 @@ module Cucumber
143
180
  end
144
181
 
145
182
  def visit_py_string(string)
146
- @builder.pre(:class => @status) do |pre|
183
+ @builder.pre(:class => 'val') do |pre|
147
184
  pre << string
148
185
  end
149
186
  end
@@ -168,8 +205,8 @@ module Cucumber
168
205
 
169
206
  def visit_table_cell_value(value, width, status)
170
207
  cell_type = @outline_row == 0 ? :th : :td
171
- attributes = {:id => "#{@row_id}_#{@col_index}"}
172
- attributes[:class] = status if status
208
+ attributes = {:id => "#{@row_id}_#{@col_index}", :class => 'val'}
209
+ attributes[:class] += " #{status}" if status
173
210
  build_cell(cell_type, value, attributes)
174
211
  @col_index += 1
175
212
  end
@@ -181,9 +218,12 @@ module Cucumber
181
218
  protected
182
219
 
183
220
  def build_step(keyword, step_match, status)
184
- step_name = step_match.format_args(lambda{|param| %{<span class="#{status}_param">#{param}</span>}})
221
+ step_name = step_match.format_args(lambda{|param| %{<span class="param">#{param}</span>}})
185
222
  @builder.div do |div|
186
- div << h("#{keyword} #{step_name}").gsub(/&lt;span class=&quot;(.*?)&quot;&gt;/, '<span class="\1">').gsub(/&lt;\/span&gt;/, '</span>')
223
+ @builder.span(keyword, :class => 'keyword')
224
+ @builder.span(:class => 'step val') do |name|
225
+ name << h(step_name).gsub(/&lt;span class=&quot;(.*?)&quot;&gt;/, '<span class="\1">').gsub(/&lt;\/span&gt;/, '</span>')
226
+ end
187
227
  end
188
228
  end
189
229
 
@@ -12,6 +12,7 @@ module Cucumber
12
12
  def initialize(step_mother, io, options)
13
13
  super(step_mother)
14
14
  @reportdir = io
15
+ @options = options
15
16
  raise "You *must* specify --out DIR for the junit formatter" unless @reportdir
16
17
  raise "Use --out DIR (not --out FILE) for the junit formatter" if File === @reportdir
17
18
  end
@@ -18,8 +18,8 @@ module Cucumber
18
18
  @io = io
19
19
  @options = options
20
20
  @delim = delim
21
- @indent = 0
22
21
  @exceptions = []
22
+ @indent = 0
23
23
  end
24
24
 
25
25
  def visit_features(features)
@@ -28,6 +28,7 @@ module Cucumber
28
28
  end
29
29
 
30
30
  def visit_feature(feature)
31
+ @exceptions = []
31
32
  @indent = 0
32
33
  if @options[:autoformat]
33
34
  file = File.join(@options[:autoformat], feature.file)
@@ -12,6 +12,7 @@ module Cucumber
12
12
  def initialize(step_mother, io, options)
13
13
  super(step_mother)
14
14
  @io = io
15
+ @options = options
15
16
  @file_names = []
16
17
  @file_colon_lines = Hash.new{|h,k| h[k] = []}
17
18
  end
@@ -5,6 +5,7 @@ module Cucumber
5
5
  def initialize(step_mother, io, options)
6
6
  super(step_mother)
7
7
  @io = io
8
+ @options = options
8
9
  @counts = Hash.new{|h,k| h[k] = 0}
9
10
  end
10
11
 
@@ -1,11 +1,15 @@
1
1
  module Cucumber
2
2
  class StepMatch
3
- attr_reader :step_definition, :args, :step_name
3
+ attr_reader :step_definition, :args
4
4
 
5
5
  def initialize(step_definition, step_name, formatted_step_name, args)
6
6
  @step_definition, @step_name, @formatted_step_name, @args = step_definition, step_name, formatted_step_name, args
7
7
  end
8
-
8
+
9
+ def name
10
+ @formatted_step_name
11
+ end
12
+
9
13
  def invoke(world, multiline_arg)
10
14
  all_args = @args.dup
11
15
  all_args << multiline_arg if multiline_arg
@@ -100,6 +100,10 @@ module Cucumber
100
100
 
101
101
  attr_writer :snippet_generator, :options, :visitor
102
102
 
103
+ def options
104
+ @options ||= {}
105
+ end
106
+
103
107
  def step_visited(step)
104
108
  steps << step unless steps.index(step)
105
109
  end
@@ -235,6 +239,13 @@ module Cucumber
235
239
  end
236
240
  end
237
241
 
242
+ def clear!
243
+ step_definitions.clear
244
+ hooks.clear
245
+ steps.clear
246
+ scenarios.clear
247
+ end
248
+
238
249
  def step_definitions
239
250
  @step_definitions ||= []
240
251
  end
@@ -274,10 +285,6 @@ module Cucumber
274
285
  @max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
275
286
  end
276
287
 
277
- def options
278
- @options || {}
279
- end
280
-
281
288
  # Creates a new world instance
282
289
  def new_world!
283
290
  return if options[:dry_run]
@@ -351,9 +358,5 @@ module Cucumber
351
358
  def scenario_visited(scenario)
352
359
  scenarios << scenario unless scenarios.index(scenario)
353
360
  end
354
-
355
- def options
356
- @options || {}
357
- end
358
361
  end
359
362
  end