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.



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

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.



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

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.



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

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.



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

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.



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

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

#aborted?Boolean

Check if scenario was aborted.

Returns:

  • (Boolean)

    True if aborted, false otherwise.



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

def aborted?
  @state == :aborted
end

#backgroundsArray<Background>

Return all backgrounds for this scenario.

They are taken from the feature containing this scenario.

Returns:



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

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.



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

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

#failed?Boolean

Check if scenario has failed.

Returns:

  • (Boolean)

    True if failed, false otherwise.



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

def failed?
  @state == :failed
end

#flaky?Boolean

Returns:

  • (Boolean)


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

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

#nameString

Return name of the scenario.

Returns:

  • (String)

    Scenario name.



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

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.



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

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

#passed?Boolean

Check if scenario has passed.

Returns:

  • (Boolean)

    True if scenario passed, false otherwise.



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

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.



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

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

#pending?Boolean

Check if scenario is pending.

Returns:

  • (Boolean)

    True if pending, false otherwise.



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

def pending?
  @state == :pending
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.



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

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

  _run(runner, reporter)

  return unless failed?

  (1..runner.retries(self)).each do
    reporter.invoke :retry_scenario, self
    reset!

    _run(runner, reporter)

    break unless failed?
  end
ensure
  reporter.invoke :after_scenario, self
end

#run?Boolean

Check if scenario was run and the state has changed.

Returns:

  • (Boolean)


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

def run?
  !@state.nil?
end

#tag_namesArray<String>

Return a list of tag names as strings.

Returns:

  • (Array<String>)

    Tag names.



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

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