Class: Lucid::AST::Scenario

Inherits:
Object show all
Includes:
HasLocation, HasSteps, Names
Defined in:
lib/lucid/ast/scenario.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes included from Names

#description, #title

Attributes included from HasSteps

#description, #gherkin_statement, #raw_steps, #title

Instance Method Summary collapse

Methods included from HasLocation

#file, #file_colon_line, #line, #location

Methods included from Names

#name

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, tags, feature_tags, keyword, title, description, raw_steps)
  @language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps = language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps
  @exception = @executed = nil
  attach_steps(@raw_steps)
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



16
17
18
# File 'lib/lucid/ast/scenario.rb', line 16

def background
  @background
end

#commentObject (readonly)

Returns the value of attribute comment.



16
17
18
# File 'lib/lucid/ast/scenario.rb', line 16

def comment
  @comment
end

#featureObject

Returns the value of attribute feature.



15
16
17
# File 'lib/lucid/ast/scenario.rb', line 15

def feature
  @feature
end

#feature_tagsObject (readonly)

Returns the value of attribute feature_tags.



14
15
16
# File 'lib/lucid/ast/scenario.rb', line 14

def feature_tags
  @feature_tags
end

#keywordObject (readonly)

Returns the value of attribute keyword.



16
17
18
# File 'lib/lucid/ast/scenario.rb', line 16

def keyword
  @keyword
end

#tagsObject (readonly)

Returns the value of attribute tags.



16
17
18
# File 'lib/lucid/ast/scenario.rb', line 16

def tags
  @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)
    tags.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

#exceptionObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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

#statusObject

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_invocationsObject



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_sexpObject



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 = @tags.to_sexp
  sexp += tags if tags.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