Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 9 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
71 lib/spinach/runner/scenario_runner.rb
@@ -1,3 +1,7 @@
+require_relative 'scenario_runner_mutex'
+require_relative 'step_runner'
+require_relative 'step_collection'
+
module Spinach
class Runner
# A Scenario Runner handles a particular scenario run.
@@ -24,15 +28,13 @@ def feature
#
# @api public
def steps
- feature.background_steps + @scenario.steps
+ all_steps = (feature.background_steps + @scenario.steps)
+ context = step_definitions_klass.new
+ @steps ||= StepCollection.new(all_steps, context)
end
- # @return [FeatureSteps]
- # The step definitions for the current feature.
- #
- # @api public
- def step_definitions
- @step_definitions ||= Spinach.find_step_definitions(feature.name).new
+ def step_definitions_klass
+ Spinach.find_step_definitions(feature.name)
end
# Runs the scenario, capturing any exception, and running the
@@ -43,48 +45,33 @@ def step_definitions
#
# @api public
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
+ scenario_runner_mutex = ScenarioRunnerMutex.new
- if @exception
- Spinach.hooks.run_on_skipped_step step
- else
- run_step(step)
- end
+ hooks.run_before_scenario @scenario
+ scenario_runner_mutex.deactivate
- Spinach.hooks.run_after_step step
- end
+ hooks.run_around_scenario @scenario do
+ scenario_runner_mutex.activate
+ run_scenario_steps
end
- raise "around_scenario hooks *must* yield" if !scenario_run && !@exception
- Spinach.hooks.run_after_scenario @scenario
- !@exception
+
+ raise "around_scenario hooks *must* yield" if !scenario_runner_mutex.active? && success?
+ hooks.run_after_scenario @scenario
+
+ !!success?
end
- # Runs a particular step.
- #
- # @param [Gherkin::AST::Step] step
- # The step to be run.
- #
- # @api semipublic
- 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
+ def hooks
+ Spinach.hooks
end
+ def run_scenario_steps
+ steps.run
+ end
+
+ def success?
+ steps.success?
+ end
end
end
end
View
21 lib/spinach/runner/scenario_runner_mutex.rb
@@ -0,0 +1,21 @@
+module Spinach
+ class Runner
+ class ScenarioRunnerMutex
+ def initialize
+ @running = false
+ end
+
+ def deactivate
+ @running = false
+ end
+
+ def activate
+ @running = true
+ end
+
+ def active?
+ !!@running
+ end
+ end
+ end
+end
View
25 lib/spinach/runner/step_collection.rb
@@ -0,0 +1,25 @@
+module Spinach
+ class Runner
+ class StepCollection
+ def initialize(steps, context)
+ @steps = steps.map do |step|
+ StepRunner.new(step, context)
+ end
+ end
+
+ def run
+ previous_step_success = true
+ @steps.each do |step|
+ step.run(previous_step_success)
+ previous_step_success = step.success?
+ end
+ end
+
+ def success?
+ @steps.all? do |step|
+ step.success?
+ end
+ end
+ end
+ end
+end
View
56 lib/spinach/runner/step_runner.rb
@@ -0,0 +1,56 @@
+module Spinach
+ class Runner
+ class StepRunner
+ def initialize(step, context)
+ @step = step
+ @success = true
+ @context = context
+ end
+
+ def run(previous_step_success)
+ hooks.run_before_step @step
+ execute unless skip?(previous_step_success)
+ hooks.run_after_step @step
+ end
+
+ def skip?(previous_step_success)
+ unless previous_step_success
+ hooks.run_on_skipped_step @step
+ end
+ !previous_step_success
+ end
+
+ # Runs a particular step.
+ #
+ # @param [Gherkin::AST::Step] step
+ # The step to be run.
+ #
+ # @api semipublic
+ def execute
+ @context.execute(@step)
+ hooks.run_on_successful_step @step, location
+ rescue *Spinach.config[:failure_exceptions] => exception
+ @success = false
+ hooks.run_on_failed_step @step, exception, location
+ rescue Spinach::StepNotDefinedException => exception
+ @success = false
+ hooks.run_on_undefined_step @step, exception
+ rescue Exception => exception
+ @success = false
+ hooks.run_on_error_step @step, exception, location
+ end
+
+ def hooks
+ Spinach.hooks
+ end
+
+ def success?
+ @success
+ end
+
+ def location
+ @context.step_location_for(@step.name)
+ end
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.