Class: Cucumber::Ast::StepInvocation

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/ast/step_invocation.rb

Overview

:nodoc:

Constant Summary collapse

BACKTRACE_FILTER_PATTERNS =
[
  /vendor\/rails|lib\/cucumber|bin\/cucumber:|lib\/rspec|gems\//
]
SEVERITY =
[:passed, :undefined, :pending, :skipped, :failed]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step, name, multiline_arg, matched_cells) ⇒ StepInvocation

Returns a new instance of StepInvocation.



21
22
23
24
# File 'lib/cucumber/ast/step_invocation.rb', line 21

def initialize(step, name, multiline_arg, matched_cells)
  @step, @name, @multiline_arg, @matched_cells = step, name, multiline_arg, matched_cells
  status!(:skipped)
end

Instance Attribute Details

#background=(value) ⇒ Object (writeonly)

Sets the attribute background

Parameters:

  • value

    the value to set the attribute background to.



10
11
12
# File 'lib/cucumber/ast/step_invocation.rb', line 10

def background=(value)
  @background = value
end

#exceptionObject

Returns the value of attribute exception.



12
13
14
# File 'lib/cucumber/ast/step_invocation.rb', line 12

def exception
  @exception
end

#matched_cellsObject (readonly)

Returns the value of attribute matched_cells.



11
12
13
# File 'lib/cucumber/ast/step_invocation.rb', line 11

def matched_cells
  @matched_cells
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/cucumber/ast/step_invocation.rb', line 11

def name
  @name
end

#reported_exceptionObject (readonly)

Returns the value of attribute reported_exception.



11
12
13
# File 'lib/cucumber/ast/step_invocation.rb', line 11

def reported_exception
  @reported_exception
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/cucumber/ast/step_invocation.rb', line 11

def status
  @status
end

#step_collection=(value) ⇒ Object (writeonly)

Sets the attribute step_collection

Parameters:

  • value

    the value to set the attribute step_collection to.



10
11
12
# File 'lib/cucumber/ast/step_invocation.rb', line 10

def step_collection=(value)
  @step_collection = value
end

Class Method Details

.worst_status(statuses) ⇒ Object



16
17
18
# File 'lib/cucumber/ast/step_invocation.rb', line 16

def worst_status(statuses)
  SEVERITY[statuses.map{|status| SEVERITY.index(status)}.max]
end

Instance Method Details

#accept(visitor) ⇒ Object



34
35
36
37
38
# File 'lib/cucumber/ast/step_invocation.rb', line 34

def accept(visitor)
  return if $cucumber_interrupted
  invoke(visitor.step_mother, visitor.options)
  visit_step_result(visitor)
end

#actual_keywordObject



127
128
129
130
131
132
133
134
# File 'lib/cucumber/ast/step_invocation.rb', line 127

def actual_keyword
  repeat_keywords = [language.but_keywords, language.and_keywords].flatten
  if repeat_keywords.index(@step.keyword) && previous
    previous.actual_keyword
  else
    keyword
  end
end

#background?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cucumber/ast/step_invocation.rb', line 26

def background?
  @background
end

#backtrace_lineObject



160
161
162
# File 'lib/cucumber/ast/step_invocation.rb', line 160

def backtrace_line
  @step.backtrace_line
end

#dom_idObject



156
157
158
# File 'lib/cucumber/ast/step_invocation.rb', line 156

def dom_id
  @step.dom_id
end

#failed(options, e, clear_backtrace) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cucumber/ast/step_invocation.rb', line 81

def failed(options, e, clear_backtrace)
  e = filter_backtrace(e)
  e.set_backtrace([]) if clear_backtrace
  e.backtrace << @step.backtrace_line unless @step.backtrace_line.nil?
  @exception = e
  if(options[:strict] || !(Undefined === e) || e.nested?)
    @reported_exception = e
  else
    @reported_exception = nil
  end
end

#file_colon_lineObject



152
153
154
# File 'lib/cucumber/ast/step_invocation.rb', line 152

def file_colon_line
  @step.file_colon_line
end

#filter_backtrace(e) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cucumber/ast/step_invocation.rb', line 93

def filter_backtrace(e)
  return e if Cucumber.use_full_backtrace
  filtered = (e.backtrace || []).reject do |line|
    BACKTRACE_FILTER_PATTERNS.detect { |p| line =~ p }
  end
  
  if Cucumber::JRUBY && e.class.name == 'NativeException'
    # JRuby's NativeException ignores #set_backtrace.
    # We're fixing it.
    e.instance_eval do
      def set_backtrace(backtrace)
        @backtrace = backtrace
      end

      def backtrace
        @backtrace
      end
    end
  end
  e.set_backtrace(filtered)
  e
end

#find_step_match!(step_mother) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cucumber/ast/step_invocation.rb', line 65

def find_step_match!(step_mother)
  return if @step_match
  begin
    @step_match = step_mother.step_match(@name)
  rescue Undefined => e
    failed(step_mother.options, e, true)
    status!(:undefined)
    @step_match = NoStepMatch.new(@step, @name)
  rescue Ambiguous => e
    failed(step_mother.options, e, false)
    status!(:failed)
    @step_match = NoStepMatch.new(@step, @name)
  end
  step_mother.step_visited(self)
end

#invoke(step_mother, options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cucumber/ast/step_invocation.rb', line 44

def invoke(step_mother, options)
  find_step_match!(step_mother)
  unless @skip_invoke || options[:dry_run] || @exception || @step_collection.exception
    @skip_invoke = true
    begin
      @step_match.invoke(@multiline_arg)
      step_mother.after_step
      status!(:passed)
    rescue Pending => e
      failed(options, e, false)
      status!(:pending)
    rescue Undefined => e
      failed(options, e, false)
      status!(:undefined)
    rescue Exception => e
      failed(options, e, false)
      status!(:failed)
    end
  end
end

#keywordObject



144
145
146
# File 'lib/cucumber/ast/step_invocation.rb', line 144

def keyword
  @step.keyword
end

#languageObject



164
165
166
# File 'lib/cucumber/ast/step_invocation.rb', line 164

def language
  @step.language
end

#multiline_argObject



148
149
150
# File 'lib/cucumber/ast/step_invocation.rb', line 148

def multiline_arg
  @step.multiline_arg
end

#previousObject



123
124
125
# File 'lib/cucumber/ast/step_invocation.rb', line 123

def previous
  @step_collection.previous_step(self)
end

#skip_invoke!Object



30
31
32
# File 'lib/cucumber/ast/step_invocation.rb', line 30

def skip_invoke!
  @skip_invoke = true
end

#source_indentObject



136
137
138
# File 'lib/cucumber/ast/step_invocation.rb', line 136

def source_indent
  @step.feature_element.source_indent(text_length)
end

#status!(status) ⇒ Object



116
117
118
119
120
121
# File 'lib/cucumber/ast/step_invocation.rb', line 116

def status!(status)
  @status = status
  @matched_cells.each do |cell|
    cell.status = status
  end
end

#text_lengthObject



140
141
142
# File 'lib/cucumber/ast/step_invocation.rb', line 140

def text_length
  @step.text_length(@name)
end

#to_sexpObject



168
169
170
# File 'lib/cucumber/ast/step_invocation.rb', line 168

def to_sexp
  [:step_invocation, @step.line, @step.keyword, @name, (@multiline_arg.nil? ? nil : @multiline_arg.to_sexp)].compact
end

#visit_step_result(visitor) ⇒ Object



40
41
42
# File 'lib/cucumber/ast/step_invocation.rb', line 40

def visit_step_result(visitor)
  visitor.visit_step_result(keyword, @step_match, @multiline_arg, @status, @reported_exception, source_indent, @background)
end