Class: Spinach::Runner::ScenarioRunner
- Inherits:
-
Object
- Object
- Spinach::Runner::ScenarioRunner
- Defined in:
- lib/spinach/runner/scenario_runner.rb
Overview
A Scenario Runner handles a particular scenario run.
Instance Method Summary collapse
-
#feature ⇒ Gherkin::AST::Feature
] The feature containing the scenario.
-
#initialize(scenario) ⇒ ScenarioRunner
constructor
A new instance of ScenarioRunner.
-
#run ⇒ true, false
Runs the scenario, capturing any exception, and running the corresponding hooks.
-
#run_step(step) ⇒ Object
Runs a particular step.
-
#step_definitions ⇒ FeatureSteps
The step definitions for the current feature.
-
#steps ⇒ Array<Gherkin::AST::Step>
An array of steps.
Constructor Details
#initialize(scenario) ⇒ ScenarioRunner
Returns a new instance of ScenarioRunner.
10 11 12 |
# File 'lib/spinach/runner/scenario_runner.rb', line 10 def initialize(scenario) @scenario = scenario end |
Instance Method Details
#feature ⇒ Gherkin::AST::Feature
Returns ] The feature containing the scenario.
18 19 20 |
# File 'lib/spinach/runner/scenario_runner.rb', line 18 def feature @scenario.feature end |
#run ⇒ true, false
Runs the scenario, capturing any exception, and running the corresponding hooks.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/spinach/runner/scenario_runner.rb', line 45 def run Spinach.hooks.run_before_scenario @scenario scenario_run = false Spinach.hooks.run_around_scenario @scenario do scenario_run = true steps.each do |step| Spinach.hooks.run_before_step step if @exception Spinach.hooks.run_on_skipped_step step else run_step(step) end Spinach.hooks.run_after_step step end end raise "around_scenario hooks *must* yield" if !scenario_run && !@exception Spinach.hooks.run_after_scenario @scenario !@exception end |
#run_step(step) ⇒ Object
Runs a particular step.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/spinach/runner/scenario_runner.rb', line 73 def run_step(step) step_location = step_definitions.step_location_for(step.name) step_definitions.execute(step) 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 |
#step_definitions ⇒ FeatureSteps
Returns The step definitions for the current feature.
34 35 36 |
# File 'lib/spinach/runner/scenario_runner.rb', line 34 def step_definitions @step_definitions ||= Spinach.find_step_definitions(feature.name).new end |
#steps ⇒ Array<Gherkin::AST::Step>
Returns An array of steps.
26 27 28 |
# File 'lib/spinach/runner/scenario_runner.rb', line 26 def steps feature.background_steps + @scenario.steps end |