Class: Spinach::Runner::ScenarioRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/runner/scenario_runner.rb

Overview

A Scenario Runner handles a particular scenario run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_name, data) ⇒ ScenarioRunner

Returns a new instance of ScenarioRunner.

Parameters:

  • feature_name (String)

    The feature name

  • data (Hash)

    The parsed feature data.



15
16
17
18
# File 'lib/spinach/runner/scenario_runner.rb', line 15

def initialize(feature_name, data)
  @feature_name = feature_name
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/spinach/runner/scenario_runner.rb', line 6

def data
  @data
end

#feature_nameObject (readonly)

Returns the value of attribute feature_name.



6
7
8
# File 'lib/spinach/runner/scenario_runner.rb', line 6

def feature_name
  @feature_name
end

Instance Method Details

#feature_stepsFeatureSteps

Returns The feature object used to run this scenario.

Returns:

  • (FeatureSteps)

    The feature object used to run this scenario.



28
29
30
# File 'lib/spinach/runner/scenario_runner.rb', line 28

def feature_steps
  @feature_steps ||= Spinach.find_feature_steps(feature_name).new
end

#runTrue, False

Runs this scenario

Returns:

  • (True, False)

    true if this scenario succeeded, false if not



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/spinach/runner/scenario_runner.rb', line 35

def run
  Spinach.hooks.run_before_scenario data
  steps.each do |step|
    Spinach.hooks.run_before_step step
    unless @exception
      begin
        step_location = feature_steps.execute_step(step['name'])
        Spinach.hooks.run_on_successful_step step, step_location
      rescue *Spinach.config[:failure_exceptions] => e
        @exception = e
        Spinach.hooks.run_on_failed_step step, @exception, step_location
      rescue Spinach::StepNotDefinedException => e
        @exception = e
        Spinach.hooks.run_on_undefined_step step, @exception
      rescue Exception => e
        @exception = e
        Spinach.hooks.run_on_error_step step, @exception, step_location
      end
    else
      Spinach.hooks.run_on_skipped_step step
    end
    Spinach.hooks.run_after_step step
  end
  Spinach.hooks.run_after_scenario data
  !@exception
end

#stepsObject



20
21
22
# File 'lib/spinach/runner/scenario_runner.rb', line 20

def steps
  @steps ||= data['steps']
end