Skip to content

Commit

Permalink
Don’t use any classes with more than two instance variables
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed Feb 12, 2012
1 parent 0ff0a54 commit 3cc0f94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
18 changes: 6 additions & 12 deletions lib/spinach/runner/scenario_runner.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ def feature
# #
# @api public # @api public
def steps def steps
step_definitions = step_definitions_klass.new
@steps ||=(feature.background_steps + @scenario.steps).map do |step| @steps ||=(feature.background_steps + @scenario.steps).map do |step|
StepRunner.new(step, step_definitions) StepRunner.new(step, step_definitions)
end end
end end


# @return [FeatureSteps]
# The step definitions for the current feature.
#
# @api public
def step_definitions
@step_definitions ||= step_definitions_klass.new
end

def step_definitions_klass def step_definitions_klass
Spinach.find_step_definitions(feature.name) Spinach.find_step_definitions(feature.name)
end end
Expand All @@ -52,25 +45,26 @@ def step_definitions_klass
# #
# @api public # @api public
def run def run
scenario_runner_mutex = ScenarioRunnerMutex.new

hooks.run_before_scenario @scenario hooks.run_before_scenario @scenario
scenario_runner_mutex.deactivate scenario_runner_mutex.deactivate

hooks.run_around_scenario @scenario do hooks.run_around_scenario @scenario do
scenario_runner_mutex.activate scenario_runner_mutex.activate
run_scenario_steps run_scenario_steps
end end

raise "around_scenario hooks *must* yield" if !scenario_runner_mutex.active? && success? raise "around_scenario hooks *must* yield" if !scenario_runner_mutex.active? && success?
hooks.run_after_scenario @scenario hooks.run_after_scenario @scenario

!!success? !!success?
end end


def hooks def hooks
Spinach.hooks Spinach.hooks
end end


def scenario_runner_mutex
@scenario_runner_mutex ||= ScenarioRunnerMutex.new
end

def run_scenario_steps def run_scenario_steps
previous_step_success = true previous_step_success = true
steps.each do |step| steps.each do |step|
Expand Down
16 changes: 8 additions & 8 deletions lib/spinach/runner/step_runner.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Runner
class StepRunner class StepRunner
def initialize(step, context) def initialize(step, context)
@step = step @step = step
@exception = false @success = true
@context = context @context = context
end end


Expand All @@ -30,22 +30,22 @@ def execute
@context.execute(@step) @context.execute(@step)
hooks.run_on_successful_step @step, location hooks.run_on_successful_step @step, location
rescue *Spinach.config[:failure_exceptions] => exception rescue *Spinach.config[:failure_exceptions] => exception
@exception = exception @success = false
hooks.run_on_failed_step @step, @exception, location hooks.run_on_failed_step @step, exception, location
rescue Spinach::StepNotDefinedException => exception rescue Spinach::StepNotDefinedException => exception
@exception = exception @success = false
hooks.run_on_undefined_step @step, @exception hooks.run_on_undefined_step @step, exception
rescue Exception => exception rescue Exception => exception
@exception = exception @success = false
hooks.run_on_error_step @step, @exception, location hooks.run_on_error_step @step, exception, location
end end


def hooks def hooks
Spinach.hooks Spinach.hooks
end end


def success? def success?
!@exception @success
end end


def location def location
Expand Down

0 comments on commit 3cc0f94

Please sign in to comment.