Class: Cucumber::Ast::Scenario
- Includes:
- FeatureElement
- Defined in:
- lib/cucumber/ast/scenario.rb
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
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.
-
#initialize(background, comment, tags, line, keyword, name, 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
Methods included from FeatureElement
#accept_hook?, #attach_steps, #backtrace_line, #file_colon_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #text_length
Constructor Details
#initialize(background, comment, tags, line, keyword, name, steps) ⇒ Scenario
Returns a new instance of Scenario.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cucumber/ast/scenario.rb', line 10 def initialize(background, comment, , line, keyword, name, steps) @background, @comment, @tags, @line, @keyword, @name = background, comment, , line, keyword, name attach_steps(steps) step_invocations = steps.map{|step| step.step_invocation} if @background @steps = @background.step_collection(step_invocations) @background.feature_elements << self else @steps = StepCollection.new(step_invocations) end 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cucumber/ast/scenario.rb', line 23 def accept(visitor) visitor.visit_comment(@comment) unless @comment.empty? visitor.(@tags) visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length)) background_failed = @background && @background.failed? skip_invoke! if background_failed skip_hooks = background_failed || @executed visitor.step_mother.before_and_after(self, skip_hooks) do visitor.visit_steps(@steps) end visitor.visit_exception(@exception, :failed) if @exception @executed = true end |
#exception ⇒ Object
Returns the first exception (if any)
53 54 55 |
# File 'lib/cucumber/ast/scenario.rb', line 53 def exception @exception || @steps.exception end |
#fail!(exception) ⇒ Object
43 44 45 |
# File 'lib/cucumber/ast/scenario.rb', line 43 def fail!(exception) @exception = exception end |
#failed? ⇒ Boolean
Returns true if one or more steps failed
39 40 41 |
# File 'lib/cucumber/ast/scenario.rb', line 39 def failed? @steps.failed? || !!@exception end |
#passed? ⇒ Boolean
Returns true if all steps passed
48 49 50 |
# File 'lib/cucumber/ast/scenario.rb', line 48 def passed? !failed? end |
#skip_invoke! ⇒ Object
63 64 65 66 67 68 |
# File 'lib/cucumber/ast/scenario.rb', line 63 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
58 59 60 61 |
# File 'lib/cucumber/ast/scenario.rb', line 58 def status return :failed if @exception @steps.status end |
#to_sexp ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cucumber/ast/scenario.rb', line 70 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 |