class Gurke::Scenario

Attributes

exception[R]

Exception that led to either pending or failed state.

@return [Exception] Exception or nil of none given.

feature[R]

The feature that contains this scenario.

@return [Feature] Parent feature.

file[R]

Return path to file containing this scenario.

@return [String] File path.

line[R]

Return line number where the scenario is defined.

@return [Fixnum] Line number.

raw[R]

@api private

steps[R]

List of this scenario's steps.

This does not include background steps.

@return [Array<Step>] Steps.

tags[R]

Public Class Methods

new(feature, file, line, tags, raw) click to toggle source

@api private

# 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

Public Instance Methods

abort!() click to toggle source

@api private

# File lib/gurke/scenario.rb, line 152
def abort!
  @exception = nil
  @state     = :aborted
end
aborted?() click to toggle source

Check if scenario was aborted.

@return [Boolean] True if aborted, false otherwise.

# File lib/gurke/scenario.rb, line 104
def aborted?
  @state == :aborted
end
backgrounds() click to toggle source

Return all backgrounds for this scenario.

They are taken from the feature containing this scenario.

@return [Array<Background>] Backgrounds.

# File lib/gurke/scenario.rb, line 64
def backgrounds
  feature.backgrounds
end
failed!(error = nil) click to toggle source

Call to mark scenario as failed.

@param error [Exception] Given an exception as reason.

# File lib/gurke/scenario.rb, line 124
def failed!(error = nil)
  @exception = error
  @state     = :failed
end
failed?() click to toggle source

Check if scenario has failed.

@return [Boolean] True if failed, false otherwise.

# File lib/gurke/scenario.rb, line 88
def failed?
  @state == :failed
end
flaky?() click to toggle source
# File lib/gurke/scenario.rb, line 139
def flaky?
  @tags.any? {|t| t.name == 'flaky' }
end
name() click to toggle source

Return name of the scenario.

@return [String] Scenario name.

# File lib/gurke/scenario.rb, line 54
def name
  raw.name
end
passed!() click to toggle source

@api private

# File lib/gurke/scenario.rb, line 145
def passed!
  @exception = nil
  @state     = :passed
end
passed?() click to toggle source

Check if scenario has passed.

@return [Boolean] True if scenario passed, false otherwise.

# File lib/gurke/scenario.rb, line 96
def passed?
  @state == :passed
end
pending!(error) click to toggle source

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

@param error [Exception] Given an exception as reason.

# File lib/gurke/scenario.rb, line 134
def pending!(error)
  @exception = error
  @state     = :pending
end
pending?() click to toggle source

Check if scenario is pending.

@return [Boolean] True if pending, false otherwise.

# File lib/gurke/scenario.rb, line 80
def pending?
  @state == :pending
end
run(runner, reporter) click to toggle source

@api private

# File lib/gurke/scenario.rb, line 159
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?() click to toggle source

Check if scenario was run and the state has changed.

# File lib/gurke/scenario.rb, line 110
def run?
  !@state.nil?
end
tag_names() click to toggle source

Return a list of tag names as strings.

@return [Array<String>] Tag names.

# File lib/gurke/scenario.rb, line 72
def tag_names
  @tag_names ||= tags.map(&:name)
end

Private Instance Methods

_run(runner, reporter) click to toggle source
# File lib/gurke/scenario.rb, line 186
def _run(runner, reporter)
  runner.hook :scenario, self, world do
    run_scenario runner, reporter
  end
end
reset!() click to toggle source
# File lib/gurke/scenario.rb, line 180
def reset!
  @state = nil
  @world = nil
  @exception = nil
end
run_scenario(runner, reporter) click to toggle source
# File lib/gurke/scenario.rb, line 192
def run_scenario(runner, reporter)
  reporter.invoke :start_scenario, self

  feature.backgrounds.run runner, reporter, self, world
  steps.run runner, reporter, self, world

  passed! unless @state
ensure
  reporter.invoke :end_scenario, self
end
world() click to toggle source
# File lib/gurke/scenario.rb, line 203
def world
  @world ||= begin
    cls = Class.new
    cls.send :include, Gurke.world

    Gurke.config.inclusions.each do |incl|
      cls.send :include, incl.mod if incl.match?(tag_names)
    end
    cls.send :include, Gurke::Steps
    cls.new
  end
end