Class: Lucid::AST::Scenario
- Includes:
- HasLocation, HasSteps, Names
- Defined in:
- lib/lucid/ast/scenario.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#feature ⇒ Object
Returns the value of attribute feature.
-
#feature_tags ⇒ Object
readonly
Returns the value of attribute feature_tags.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Attributes included from Names
Attributes included from HasSteps
#description, #gherkin_statement, #raw_steps, #title
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#exception ⇒ Object
Returns the first exception (if any).
- #execute(runtime, visitor) ⇒ Object
- #fail!(exception) ⇒ Object
-
#failed? ⇒ Boolean
Returns true if one or more steps failed.
-
#initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, 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.
- #step_invocations ⇒ Object
- #to_sexp ⇒ Object
- #to_units(background) ⇒ Object
- #with_visitor(visitor) ⇒ Object
Methods included from HasLocation
#file, #file_colon_line, #line, #location
Methods included from Names
Methods included from HasSteps
#accept_hook?, #attach_steps, #backtrace_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #source_tag_names, #source_tags, #text_length
Constructor Details
#initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps) ⇒ Scenario
Returns a new instance of Scenario.
18 19 20 21 22 |
# File 'lib/lucid/ast/scenario.rb', line 18 def initialize(language, location, background, comment, , , keyword, title, description, raw_steps) @language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps = language, location, background, comment, , , keyword, title, description, raw_steps @exception = @executed = nil attach_steps(@raw_steps) end |
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute background.
16 17 18 |
# File 'lib/lucid/ast/scenario.rb', line 16 def background @background end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
16 17 18 |
# File 'lib/lucid/ast/scenario.rb', line 16 def comment @comment end |
#feature ⇒ Object
Returns the value of attribute feature.
15 16 17 |
# File 'lib/lucid/ast/scenario.rb', line 15 def feature @feature end |
#feature_tags ⇒ Object (readonly)
Returns the value of attribute feature_tags.
14 15 16 |
# File 'lib/lucid/ast/scenario.rb', line 14 def @feature_tags end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
16 17 18 |
# File 'lib/lucid/ast/scenario.rb', line 16 def keyword @keyword end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
16 17 18 |
# File 'lib/lucid/ast/scenario.rb', line 16 def @tags end |
Instance Method Details
#accept(visitor) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lucid/ast/scenario.rb', line 24 def accept(visitor) background.accept(visitor) visitor.visit_feature_element(self) do comment.accept(visitor) .accept(visitor) visitor.visit_scenario_name(keyword, name, file_colon_line, source_indent(first_line_length)) skip_invoke! if background.failed? with_visitor(visitor) do execute(visitor.runtime, visitor) end @executed = true end end |
#exception ⇒ Object
Returns the first exception (if any).
67 68 69 |
# File 'lib/lucid/ast/scenario.rb', line 67 def exception @exception || step_invocations.exception end |
#execute(runtime, visitor) ⇒ Object
40 41 42 43 44 |
# File 'lib/lucid/ast/scenario.rb', line 40 def execute(runtime, visitor) runtime.with_hooks(self, skip_hooks?) do step_invocations.accept(visitor) end end |
#fail!(exception) ⇒ Object
55 56 57 58 59 |
# File 'lib/lucid/ast/scenario.rb', line 55 def fail!(exception) @exception = exception @current_visitor.visit_exception(@exception, :failed) skip_invoke! end |
#failed? ⇒ Boolean
Returns true if one or more steps failed.
51 52 53 |
# File 'lib/lucid/ast/scenario.rb', line 51 def failed? step_invocations.failed? || !!@exception end |
#passed? ⇒ Boolean
Returns true if all steps passed.
62 63 64 |
# File 'lib/lucid/ast/scenario.rb', line 62 def passed? !failed? end |
#skip_invoke! ⇒ Object
93 94 95 |
# File 'lib/lucid/ast/scenario.rb', line 93 def skip_invoke! step_invocations.skip_invoke! end |
#status ⇒ Object
Returns the status.
72 73 74 75 |
# File 'lib/lucid/ast/scenario.rb', line 72 def status return :failed if @exception step_invocations.status end |
#step_invocations ⇒ Object
97 98 99 |
# File 'lib/lucid/ast/scenario.rb', line 97 def step_invocations @step_invocation ||= @background.create_step_invocations(my_step_invocations) end |
#to_sexp ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/lucid/ast/scenario.rb', line 77 def to_sexp sexp = [:scenario, line, @keyword, name] comment = @comment.to_sexp sexp += [comment] if comment = @tags.to_sexp sexp += if .any? sexp += step_invocations.to_sexp if step_invocations.any? sexp end |
#to_units(background) ⇒ Object
46 47 48 |
# File 'lib/lucid/ast/scenario.rb', line 46 def to_units(background) [Unit.new(step_invocations)] end |
#with_visitor(visitor) ⇒ Object
87 88 89 90 91 |
# File 'lib/lucid/ast/scenario.rb', line 87 def with_visitor(visitor) @current_visitor = visitor yield @current_visitor = nil end |