class Gurke::Scenario
Attributes
Exception that led to either pending or failed state.
@return [Exception] Exception or nil of none given.
The feature that contains this scenario.
@return [Feature] Parent feature.
Return path to file containing this scenario.
@return [String] File path.
Return line number where the scenario is defined.
@return [Fixnum] Line number.
@api private
Public Class Methods
@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
@api private
# File lib/gurke/scenario.rb, line 152 def abort! @exception = nil @state = :aborted end
Check if scenario was aborted.
@return [Boolean] True if aborted, false otherwise.
# File lib/gurke/scenario.rb, line 104 def aborted? @state == :aborted end
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
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
Check if scenario has failed.
@return [Boolean] True if failed, false otherwise.
# File lib/gurke/scenario.rb, line 88 def failed? @state == :failed end
# File lib/gurke/scenario.rb, line 139 def flaky? @tags.any? {|t| t.name == 'flaky' } end
Return name of the scenario.
@return [String] Scenario
name.
# File lib/gurke/scenario.rb, line 54 def name raw.name end
@api private
# File lib/gurke/scenario.rb, line 145 def passed! @exception = nil @state = :passed end
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
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
Check if scenario is pending.
@return [Boolean] True if pending, false otherwise.
# File lib/gurke/scenario.rb, line 80 def pending? @state == :pending end
@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
Check if scenario was run and the state has changed.
# File lib/gurke/scenario.rb, line 110 def run? !@state.nil? end
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
# File lib/gurke/scenario.rb, line 186 def _run(runner, reporter) runner.hook :scenario, self, world do run_scenario runner, reporter end end
# File lib/gurke/scenario.rb, line 180 def reset! @state = nil @world = nil @exception = nil end
# 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
# 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