Class: Spinach::Runner::Scenario

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/spinach/runner/scenario.rb

Overview

A Scenario Runner handles a particular scenario run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_name, feature, data) ⇒ Scenario

Returns a new instance of Scenario.

Parameters:

  • feature (Feature)

    The feature that contains the steps.

  • data (Hash)

    The parsed feature data.



27
28
29
30
31
# File 'lib/spinach/runner/scenario.rb', line 27

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/spinach/runner/scenario.rb', line 8

def data
  @data
end

#featureObject (readonly)

Returns the value of attribute feature.



8
9
10
# File 'lib/spinach/runner/scenario.rb', line 8

def feature
  @feature
end

#feature_nameObject (readonly)

Returns the value of attribute feature_name.



8
9
10
# File 'lib/spinach/runner/scenario.rb', line 8

def feature_name
  @feature_name
end

Instance Method Details

#runTrue, False

Runs this scenario

Returns:

  • (True, False)

    true if this scenario succeeded, false if not



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/spinach/runner/scenario.rb', line 40

def run
  run_hook :before_run, data
  feature.run_hook :before_scenario, data
  steps.each do |step|
    feature.run_hook :before_step, step
    unless @exception
      begin
        step_location = feature.execute_step(step['name'])
        run_hook :on_successful_step, step, step_location
      rescue *Spinach.config[:failure_exceptions] => e
        @exception = e
        run_hook :on_failed_step, step, @exception, step_location
      rescue Spinach::StepNotDefinedException => e
        @exception = e
        run_hook :on_undefined_step, step, @exception
      rescue Exception => e
        @exception = e
        run_hook :on_error_step, step, @exception, step_location
      end
    else
      run_hook :on_skipped_step, step
    end
    feature.run_hook :after_step, step
  end
  feature.run_hook :after_scenario, data
  run_hook :after_run, data
  !@exception
end

#stepsObject



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

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