Class: Lucid::AST::StepInvocation
- Defined in:
- lib/lucid/ast/step_invocation.rb
Defined Under Namespace
Classes: Keywords
Constant Summary collapse
- SEVERITY =
[:passed, :undefined, :pending, :skipped, :failed]
- BACKTRACE_FILTER_PATTERNS =
[/vendor\/rails|lib\/lucid|bin\/lucid:|lib\/rspec|gems\/|minitest|test\/unit|\/\.gem\//]
- PWD_PATTERN =
/#{Regexp.escape(Dir.pwd)}\//m
Instance Attribute Summary collapse
-
#background ⇒ Object
writeonly
Sets the attribute background.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#matched_cells ⇒ Object
readonly
Returns the value of attribute matched_cells.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reported_exception ⇒ Object
readonly
Returns the value of attribute reported_exception.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#step_collection ⇒ Object
writeonly
Sets the attribute step_collection.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #actual_keyword ⇒ Object
- #background? ⇒ Boolean
- #backtrace_line ⇒ Object
- #dom_id ⇒ Object
- #failed(context, e, clear_backtrace) ⇒ Object
- #file_colon_line ⇒ Object
- #filter_backtrace(e) ⇒ Object
- #find_step_match!(runtime, context) ⇒ Object
- #gherkin_statement ⇒ Object
-
#initialize(step, name, multiline_arg, matched_cells) ⇒ StepInvocation
constructor
A new instance of StepInvocation.
- #invoke(runtime, context) ⇒ Object
- #keyword ⇒ Object
- #language ⇒ Object
- #multiline_arg ⇒ Object
- #previous ⇒ Object
- #skip_invoke! ⇒ Object
- #source_indent ⇒ Object
- #status!(status) ⇒ Object
- #text_length ⇒ Object
- #to_sexp ⇒ Object
Constructor Details
#initialize(step, name, multiline_arg, matched_cells) ⇒ StepInvocation
Returns a new instance of StepInvocation.
20 21 22 23 24 |
# File 'lib/lucid/ast/step_invocation.rb', line 20 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
9 10 11 |
# File 'lib/lucid/ast/step_invocation.rb', line 9 def background=(value) @background = value end |
#exception ⇒ Object
Returns the value of attribute exception.
11 12 13 |
# File 'lib/lucid/ast/step_invocation.rb', line 11 def exception @exception end |
#matched_cells ⇒ Object (readonly)
Returns the value of attribute matched_cells.
10 11 12 |
# File 'lib/lucid/ast/step_invocation.rb', line 10 def matched_cells @matched_cells end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/lucid/ast/step_invocation.rb', line 10 def name @name end |
#reported_exception ⇒ Object (readonly)
Returns the value of attribute reported_exception.
10 11 12 |
# File 'lib/lucid/ast/step_invocation.rb', line 10 def reported_exception @reported_exception end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/lucid/ast/step_invocation.rb', line 10 def status @status end |
#step_collection=(value) ⇒ Object (writeonly)
Sets the attribute step_collection
9 10 11 |
# File 'lib/lucid/ast/step_invocation.rb', line 9 def step_collection=(value) @step_collection = value end |
Class Method Details
Instance Method Details
#accept(visitor) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/lucid/ast/step_invocation.rb', line 34 def accept(visitor) visitor.visit_step(self) do invoke(visitor.runtime, visitor.context) step_result.accept(visitor) end end |
#actual_keyword ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/lucid/ast/step_invocation.rb', line 132 def actual_keyword keywords = Keywords.new(language) if keywords.repeat_keyword?(keyword) && previous previous.actual_keyword else keyword == '* ' ? keywords.star_code_keyword : keyword end end |
#background? ⇒ Boolean
26 27 28 |
# File 'lib/lucid/ast/step_invocation.rb', line 26 def background? @background end |
#backtrace_line ⇒ Object
190 191 192 |
# File 'lib/lucid/ast/step_invocation.rb', line 190 def backtrace_line @step.backtrace_line end |
#dom_id ⇒ Object
186 187 188 |
# File 'lib/lucid/ast/step_invocation.rb', line 186 def dom_id @step.dom_id end |
#failed(context, e, clear_backtrace) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lucid/ast/step_invocation.rb', line 82 def failed(context, 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(context.strict? || !(Undefined === e) || e.nested?) @reported_exception = e else @reported_exception = nil end end |
#file_colon_line ⇒ Object
182 183 184 |
# File 'lib/lucid/ast/step_invocation.rb', line 182 def file_colon_line @step.file_colon_line end |
#filter_backtrace(e) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/lucid/ast/step_invocation.rb', line 102 def filter_backtrace(e) return e if Lucid.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['LUCID_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, context) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lucid/ast/step_invocation.rb', line 66 def find_step_match!(runtime, context) return if @step_match begin @step_match = runtime.step_match(@name) rescue Undefined => e failed(context, e, true) status!(:undefined) @step_match = NoStepMatch.new(@step, @name) rescue Ambiguous => e failed(context, e, false) status!(:failed) @step_match = NoStepMatch.new(@step, @name) end runtime.step_visited(self) end |
#gherkin_statement ⇒ Object
198 199 200 |
# File 'lib/lucid/ast/step_invocation.rb', line 198 def gherkin_statement @step.gherkin_statement end |
#invoke(runtime, context) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lucid/ast/step_invocation.rb', line 41 def invoke(runtime, context) find_step_match!(runtime, context) unless @skip_invoke || context.dry_run? || @exception || @step_collection.exception @skip_invoke = true begin @step_match.invoke(@multiline_arg) runtime.after_step status!(:passed) rescue Pending => e failed(context, e, false) status!(:pending) rescue Undefined => e failed(context, e, false) status!(:undefined) rescue Lucid::AST::Table::Different => e @different_table = e.table failed(context, e, false) status!(:failed) rescue Exception => e failed(context, e, false) status!(:failed) end end end |
#keyword ⇒ Object
174 175 176 |
# File 'lib/lucid/ast/step_invocation.rb', line 174 def keyword @step.keyword end |
#language ⇒ Object
194 195 196 |
# File 'lib/lucid/ast/step_invocation.rb', line 194 def language @step.language || raise("Language is required on #{@step}") end |
#multiline_arg ⇒ Object
178 179 180 |
# File 'lib/lucid/ast/step_invocation.rb', line 178 def multiline_arg @step.multiline_arg end |
#previous ⇒ Object
128 129 130 |
# File 'lib/lucid/ast/step_invocation.rb', line 128 def previous @step_collection.previous_step(self) end |
#skip_invoke! ⇒ Object
30 31 32 |
# File 'lib/lucid/ast/step_invocation.rb', line 30 def skip_invoke! @skip_invoke = true end |
#source_indent ⇒ Object
166 167 168 |
# File 'lib/lucid/ast/step_invocation.rb', line 166 def source_indent @step.feature_element.source_indent(text_length) end |
#status!(status) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/lucid/ast/step_invocation.rb', line 121 def status!(status) @status = status @matched_cells.each do |cell| cell.status = status end end |
#text_length ⇒ Object
170 171 172 |
# File 'lib/lucid/ast/step_invocation.rb', line 170 def text_length @step.text_length(@name) end |
#to_sexp ⇒ Object
202 203 204 |
# File 'lib/lucid/ast/step_invocation.rb', line 202 def to_sexp [:step_invocation, @step.line, @step.keyword, @name, (@multiline_arg.nil? ? nil : @multiline_arg.to_sexp)].compact end |