Class: Cucumber::Ast::Scenario

Inherits:
Object
  • Object
show all
Includes:
FeatureElement
Defined in:
lib/cucumber/ast/scenario.rb

Overview

:nodoc:

Defined Under Namespace

Classes: EmptyBackground

Instance Attribute Summary collapse

Attributes included from FeatureElement

#feature

Instance Method Summary collapse

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, #source_tag_names, #tag_count, #text_length

Constructor Details

#initialize(background, comment, tags, line, keyword, name, steps) ⇒ Scenario

Returns a new instance of Scenario.



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

def initialize(background, comment, tags, line, keyword, name, steps)
  @background = background || EmptyBackground.new
  @comment, @tags, @line, @keyword, @name = comment, tags, line, keyword, name
  attach_steps(steps)

  step_invocations = steps.map{|step| step.step_invocation}
  @steps = @background.step_collection(step_invocations)
  @background.feature_elements << self
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



8
9
10
# File 'lib/cucumber/ast/scenario.rb', line 8

def line
  @line
end

#nameObject (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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cucumber/ast/scenario.rb', line 34

def accept(visitor)
  return if $cucumber_interrupted
  
  with_visitor(visitor) do
    visitor.visit_comment(@comment) unless @comment.empty?
    visitor.visit_tags(@tags)
    visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))

    skip_invoke! if @background.failed?
    visitor.step_mother.before_and_after(self, skip_hooks?) do
      skip_invoke! if failed?
      visitor.visit_steps(@steps)
    end
    @executed = true
  end
end

#exceptionObject

Returns the first exception (if any)



67
68
69
# File 'lib/cucumber/ast/scenario.rb', line 67

def exception
  @exception || @steps.exception
end

#fail!(exception) ⇒ Object



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

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

#failed?Boolean

Returns true if one or more steps failed

Returns:

  • (Boolean)


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

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

#passed?Boolean

Returns true if all steps passed

Returns:

  • (Boolean)


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

def passed?
  !failed?
end

#skip_invoke!Object



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

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

#statusObject

Returns the status



72
73
74
75
# File 'lib/cucumber/ast/scenario.rb', line 72

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

#to_sexpObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/cucumber/ast/scenario.rb', line 84

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