Class: Cucumber::Ast::StepInvocation

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

Overview

:nodoc:

Constant Summary collapse

SEVERITY =
[:passed, :undefined, :pending, :skipped, :failed]
BACKTRACE_FILTER_PATTERNS =

This constant is appended to by Cuke4Duke. Do not change its name

[/vendor\/rails|lib\/cucumber|bin\/cucumber:|lib\/rspec|gems\/|minitest|test\/unit|lib\/ruby/]
PWD_PATTERN =
/#{Regexp.escape(Dir.pwd)}\//m

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.



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

def initialize(step, name, multiline_arg, matched_cells)
  @step, @name, @multiline_arg, @matched_cells = step, name, multiline_arg, matched_cells
  status!(:skipped)
  @skip_invoke = @exception = @step_match = @different_table = @reported_exception = @background = nil
end

Instance Attribute Details

#background=(value) ⇒ Object (writeonly)

Sets the attribute background

Parameters:

  • value

    the value to set the attribute background to.



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

def background=(value)
  @background = value
end

#exceptionObject

Returns the value of attribute exception.



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

def exception
  @exception
end

#matched_cellsObject (readonly)

Returns the value of attribute matched_cells.



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

def matched_cells
  @matched_cells
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#reported_exceptionObject (readonly)

Returns the value of attribute reported_exception.



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

def reported_exception
  @reported_exception
end

#statusObject (readonly)

Returns the value of attribute status.



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

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.



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

def step_collection=(value)
  @step_collection = value
end

Class Method Details

.worst_status(statuses) ⇒ Object



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

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

Instance Method Details

#accept(visitor) ⇒ Object



36
37
38
39
40
# File 'lib/cucumber/ast/step_invocation.rb', line 36

def accept(visitor)
  return if Cucumber.wants_to_quit
  invoke(visitor.runtime, visitor.configuration)
  visit_step_result(visitor)
end

#actual_keywordObject



146
147
148
149
150
151
152
153
# File 'lib/cucumber/ast/step_invocation.rb', line 146

def actual_keyword
  repeat_keywords = rubify([language.keywords('but'), language.keywords('and')]).flatten.uniq.reject{|kw| kw == '* '}
  if repeat_keywords.index(@step.keyword) && previous
    previous.actual_keyword
  else
    keyword == '* ' ? language.code_keywords.first : keyword
  end
end

#background?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cucumber/ast/step_invocation.rb', line 28

def background?
  @background
end

#backtrace_lineObject



179
180
181
# File 'lib/cucumber/ast/step_invocation.rb', line 179

def backtrace_line
  @step.backtrace_line
end

#dom_idObject



175
176
177
# File 'lib/cucumber/ast/step_invocation.rb', line 175

def dom_id
  @step.dom_id
end

#failed(configuration, e, clear_backtrace) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cucumber/ast/step_invocation.rb', line 96

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

#file_colon_lineObject



171
172
173
# File 'lib/cucumber/ast/step_invocation.rb', line 171

def file_colon_line
  @step.file_colon_line
end

#filter_backtrace(e) ⇒ Object

This is to work around double “:in ” segments in JRuby backtraces. JRuby bug?



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cucumber/ast/step_invocation.rb', line 116

def filter_backtrace(e)
  return e if Cucumber.use_full_backtrace
  e.backtrace.each{|line| line.gsub!(PWD_PATTERN, "./")}

  filtered = (e.backtrace || []).reject do |line|
    BACKTRACE_FILTER_PATTERNS.detect { |p| line =~ p }
  end

  if ENV['CUCUMBER_TRUNCATE_OUTPUT']
    # Strip off file locations
    filtered = filtered.map do |line|
      line =~ /(.*):in `/ ? $1 : line
    end
  end

  e.set_backtrace(filtered)
  e
end

#find_step_match!(runtime, configuration) ⇒ Object



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

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

#gherkin_statementObject



187
188
189
# File 'lib/cucumber/ast/step_invocation.rb', line 187

def gherkin_statement
  @step.gherkin_statement
end

#invoke(runtime, configuration) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cucumber/ast/step_invocation.rb', line 55

def invoke(runtime, configuration)
  find_step_match!(runtime, configuration)
  unless @skip_invoke || configuration.dry_run? || @exception || @step_collection.exception
    @skip_invoke = true
    begin
      @step_match.invoke(@multiline_arg)
      runtime.after_step
      status!(:passed)
    rescue Pending => e
      failed(configuration, e, false)
      status!(:pending)
    rescue Undefined => e
      failed(configuration, e, false)
      status!(:undefined)
    rescue Cucumber::Ast::Table::Different => e
      @different_table = e.table
      failed(configuration, e, false)
      status!(:failed)
    rescue Exception => e
      failed(configuration, e, false)
      status!(:failed)
    end
  end
end

#keywordObject



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

def keyword
  @step.keyword
end

#languageObject



183
184
185
# File 'lib/cucumber/ast/step_invocation.rb', line 183

def language
  @step.language || raise("Language is required on #{@step}")
end

#multiline_argObject



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

def multiline_arg
  @step.multiline_arg
end

#previousObject



142
143
144
# File 'lib/cucumber/ast/step_invocation.rb', line 142

def previous
  @step_collection.previous_step(self)
end

#skip_invoke!Object



32
33
34
# File 'lib/cucumber/ast/step_invocation.rb', line 32

def skip_invoke!
  @skip_invoke = true
end

#source_indentObject



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

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

#status!(status) ⇒ Object



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

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

#text_lengthObject



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

def text_length
  @step.text_length(@name)
end

#to_sexpObject



191
192
193
# File 'lib/cucumber/ast/step_invocation.rb', line 191

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



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cucumber/ast/step_invocation.rb', line 42

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