Class: Cucumber::Ast::Scenario
- Includes:
- FeatureElement
- Defined in:
- lib/cucumber/ast/scenario.rb
Overview
:nodoc:
Defined Under Namespace
Classes: EmptyBackground
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from FeatureElement
#feature, #gherkin_statement, #raw_steps
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#exception ⇒ Object
Returns the first exception (if any).
- #fail!(exception) ⇒ Object
-
#failed? ⇒ Boolean
Returns true if one or more steps failed.
- #init ⇒ Object
-
#initialize(background, comment, tags, line, keyword, name, raw_steps) ⇒ Scenario
constructor
A new instance of Scenario.
-
#passed? ⇒ Boolean
Returns true if all steps passed.
- #skip_invoke! ⇒ Object
-
#status ⇒ Object
Returns the status.
- #to_sexp ⇒ Object
- #with_visitor(visitor) ⇒ Object
Methods included from FeatureElement
#accept_hook?, #add_step, #attach_steps, #backtrace_line, #file_colon_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #source_tag_names, #text_length
Constructor Details
#initialize(background, comment, tags, line, keyword, name, raw_steps) ⇒ Scenario
Returns a new instance of Scenario.
27 28 29 30 31 |
# File 'lib/cucumber/ast/scenario.rb', line 27 def initialize(background, comment, , line, keyword, name, raw_steps) @background = background || EmptyBackground.new @comment, @tags, @line, @keyword, @name, @raw_steps = comment, , line, keyword, name, raw_steps @exception = @executed = nil end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
8 9 10 |
# File 'lib/cucumber/ast/scenario.rb', line 8 def line @line end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/cucumber/ast/scenario.rb', line 8 def name @name end |
Instance Method Details
#accept(visitor) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cucumber/ast/scenario.rb', line 42 def accept(visitor) return if Cucumber.wants_to_quit with_visitor(visitor) do visitor.visit_comment(@comment) unless @comment.empty? visitor.(@tags) visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length)) skip_invoke! if @background.failed? visitor.step_mother.with_hooks(self, skip_hooks?) do skip_invoke! if failed? visitor.visit_steps(@steps) end @executed = true end end |
#exception ⇒ Object
Returns the first exception (if any)
75 76 77 |
# File 'lib/cucumber/ast/scenario.rb', line 75 def exception @exception || @steps.exception end |
#fail!(exception) ⇒ Object
64 65 66 67 |
# File 'lib/cucumber/ast/scenario.rb', line 64 def fail!(exception) @exception = exception @current_visitor.visit_exception(@exception, :failed) end |
#failed? ⇒ Boolean
Returns true if one or more steps failed
60 61 62 |
# File 'lib/cucumber/ast/scenario.rb', line 60 def failed? @steps.failed? || !!@exception end |
#init ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/cucumber/ast/scenario.rb', line 33 def init return if @steps @background.init @background.feature_elements << self attach_steps(@raw_steps) step_invocations = @raw_steps.map{|step| step.step_invocation} @steps = @background.step_collection(step_invocations) end |
#passed? ⇒ Boolean
Returns true if all steps passed
70 71 72 |
# File 'lib/cucumber/ast/scenario.rb', line 70 def passed? !failed? end |
#skip_invoke! ⇒ Object
85 86 87 88 89 90 |
# File 'lib/cucumber/ast/scenario.rb', line 85 def skip_invoke! @steps.each{|step_invocation| step_invocation.skip_invoke!} @feature.next_feature_element(self) do |next_one| next_one.skip_invoke! end end |
#status ⇒ Object
Returns the status
80 81 82 83 |
# File 'lib/cucumber/ast/scenario.rb', line 80 def status return :failed if @exception @steps.status end |
#to_sexp ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cucumber/ast/scenario.rb', line 92 def to_sexp sexp = [:scenario, @line, @keyword, @name] comment = @comment.to_sexp sexp += [comment] if comment = @tags.to_sexp sexp += if .any? steps = @steps.to_sexp sexp += steps if steps.any? sexp end |
#with_visitor(visitor) ⇒ Object
104 105 106 107 108 |
# File 'lib/cucumber/ast/scenario.rb', line 104 def with_visitor(visitor) @current_visitor = visitor yield @current_visitor = nil end |