Class: Gurke::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/gurke/scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, file, line, tags, raw) ⇒ Scenario

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scenario.



40
41
42
43
44
45
46
47
48
# File 'lib/gurke/scenario.rb', line 40

def initialize(feature, file, line, tags, raw)
  @feature = feature
  @steps   = RunList.new
  @file    = file
  @line    = line
  @tags    = tags
  @raw     = raw
  @state   = nil
end

Instance Attribute Details

#exceptionException (readonly)

Exception that led to either pending or failed state.

Returns:

  • (Exception)

    Exception or nil of none given.



118
119
120
# File 'lib/gurke/scenario.rb', line 118

def exception
  @exception
end

#featureFeature (readonly)

The feature that contains this scenario.

Returns:



22
23
24
# File 'lib/gurke/scenario.rb', line 22

def feature
  @feature
end

#fileString (readonly)

Return path to file containing this scenario.

Returns:

  • (String)

    File path.



10
11
12
# File 'lib/gurke/scenario.rb', line 10

def file
  @file
end

#lineFixnum (readonly)

Return line number where the scenario is defined.

Returns:

  • (Fixnum)

    Line number.



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

def line
  @line
end

#rawObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/gurke/scenario.rb', line 36

def raw
  @raw
end

#stepsArray<Step> (readonly)

List of this scenario’s steps.

This does not include background steps.

Returns:

  • (Array<Step>)

    Steps.



30
31
32
# File 'lib/gurke/scenario.rb', line 30

def steps
  @steps
end

#tagsObject (readonly)

Returns the value of attribute tags.



33
34
35
# File 'lib/gurke/scenario.rb', line 33

def tags
  @tags
end

Instance Method Details

#abort!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



152
153
154
155
# File 'lib/gurke/scenario.rb', line 152

def abort!
  @exception = nil
  @state     = :aborted
end

#aborted?Boolean

Check if scenario was aborted.

Returns:

  • (Boolean)

    True if aborted, false otherwise.



104
105
106
# File 'lib/gurke/scenario.rb', line 104

def aborted?
  @state == :aborted
end

#backgroundsArray<Background>

Return all backgrounds for this scenario.

They are taken from the feature containing this scenario.

Returns:



64
65
66
# File 'lib/gurke/scenario.rb', line 64

def backgrounds
  feature.backgrounds
end

#failed!(error = nil) ⇒ Object

Call to mark scenario as failed.

Parameters:

  • error (Exception) (defaults to: nil)

    Given an exception as reason.



124
125
126
127
# File 'lib/gurke/scenario.rb', line 124

def failed!(error = nil)
  @exception = error
  @state     = :failed
end

#failed?Boolean

Check if scenario has failed.

Returns:

  • (Boolean)

    True if failed, false otherwise.



88
89
90
# File 'lib/gurke/scenario.rb', line 88

def failed?
  @state == :failed
end

#nameString

Return name of the scenario.

Returns:

  • (String)

    Scenario name.



54
55
56
# File 'lib/gurke/scenario.rb', line 54

def name
  raw.name
end

#passed!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



145
146
147
148
# File 'lib/gurke/scenario.rb', line 145

def passed!
  @exception = nil
  @state     = :passed
end

#passed?Boolean

Check if scenario has passed.

Returns:

  • (Boolean)

    True if scenario passed, false otherwise.



96
97
98
# File 'lib/gurke/scenario.rb', line 96

def passed?
  @state == :passed
end

#pending!(error) ⇒ Object

Call to mark scenario as pending. Will do nothing if scenario is already failed.

Parameters:

  • error (Exception)

    Given an exception as reason.



134
135
136
137
# File 'lib/gurke/scenario.rb', line 134

def pending!(error)
  @exception = error
  @state     = :pending
end

#pending?Boolean

Check if scenario is pending.

Returns:

  • (Boolean)

    True if pending, false otherwise.



80
81
82
# File 'lib/gurke/scenario.rb', line 80

def pending?
  @state == :pending
end

#retryable?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/gurke/scenario.rb', line 139

def retryable?
  @tags.any? {|t| t.name == 'flaky' }
end

#run(runner, reporter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/gurke/scenario.rb', line 159

def run(runner, reporter)
  reporter.invoke :before_scenario, self

  runner.hook :scenario, self, world do
    run_scenario runner, reporter
  end

  if failed? && retryable?
    reporter.invoke :retry_scenario, self
    reset!

    runner.hook :scenario, self, world do
      run_scenario runner, reporter
    end
  end
ensure
  reporter.invoke :after_scenario, self
end

#run?Boolean

Check if scenario was run and the state has changed.

Returns:

  • (Boolean)


110
111
112
# File 'lib/gurke/scenario.rb', line 110

def run?
  !@state.nil?
end

#tag_namesArray<String>

Return a list of tag names as strings.

Returns:

  • (Array<String>)

    Tag names.



72
73
74
# File 'lib/gurke/scenario.rb', line 72

def tag_names
  @tag_names ||= tags.map(&:name)
end