Class: Cucumber::Ast::Scenario

Inherits:
Object
  • Object
show all
Includes:
HasLocation, HasSteps, Names
Defined in:
lib/cucumber/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.



17
18
19
20
21
# File 'lib/cucumber/ast/scenario.rb', line 17

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

#featureObject

Returns the value of attribute feature.



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

def feature
  @feature
end

#feature_tagsObject (readonly)

Returns the value of attribute feature_tags.



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

def feature_tags
  @feature_tags
end

Instance Method Details

#accept(visitor) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cucumber/ast/scenario.rb', line 23

def accept(visitor)
  return if Cucumber.wants_to_quit

  visitor.visit_comment(@comment) unless @comment.empty?
  visitor.visit_tags(@tags)
  visitor.visit_scenario_name(@keyword, name, file_colon_line, source_indent(first_line_length))

  skip_invoke! if @background.failed?
  with_visitor(visitor) do
    visitor.execute(self, skip_hooks?)
  end
  @executed = true
end

#exceptionObject

Returns the first exception (if any)



57
58
59
# File 'lib/cucumber/ast/scenario.rb', line 57

def exception
  @exception || steps.exception
end

#fail!(exception) ⇒ Object



46
47
48
49
# File 'lib/cucumber/ast/scenario.rb', line 46

def fail!(exception)
  @exception = exception
  @current_visitor.visit_exception(@exception, :failed)
end

#failed?Boolean

Returns true if one or more steps failed

Returns:

  • (Boolean)


42
43
44
# File 'lib/cucumber/ast/scenario.rb', line 42

def failed?
  steps.failed? || !!@exception
end

#passed?Boolean

Returns true if all steps passed

Returns:

  • (Boolean)


52
53
54
# File 'lib/cucumber/ast/scenario.rb', line 52

def passed?
  !failed?
end

#skip_invoke!Object



83
84
85
# File 'lib/cucumber/ast/scenario.rb', line 83

def skip_invoke!
  steps.skip_invoke!
end

#statusObject

Returns the status



62
63
64
65
# File 'lib/cucumber/ast/scenario.rb', line 62

def status
  return :failed if @exception
  steps.status
end

#stepsObject



87
88
89
# File 'lib/cucumber/ast/scenario.rb', line 87

def steps
  @steps ||= @background.step_collection(step_invocations)
end

#to_sexpObject



67
68
69
70
71
72
73
74
75
# File 'lib/cucumber/ast/scenario.rb', line 67

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 += steps.to_sexp if steps.any?
  sexp
end

#to_units(background) ⇒ Object



37
38
39
# File 'lib/cucumber/ast/scenario.rb', line 37

def to_units(background)
  [Unit.new(background.step_invocations + step_invocations)]
end

#with_visitor(visitor) ⇒ Object



77
78
79
80
81
# File 'lib/cucumber/ast/scenario.rb', line 77

def with_visitor(visitor)
  @current_visitor = visitor
  yield
  @current_visitor = nil
end