Permalink
Browse files

Use first-class collections

  • Loading branch information...
oriolgual committed Feb 12, 2012
1 parent 3cc0f94 commit 913db701e9e28966491966fd85365495490034df
Showing with 31 additions and 12 deletions.
  1. +6 −12 lib/spinach/runner/scenario_runner.rb
  2. +25 −0 lib/spinach/runner/step_collection.rb
@@ -1,5 +1,6 @@
require_relative 'scenario_runner_mutex'
require_relative 'step_runner'
+require_relative 'step_collection'
module Spinach
class Runner
@@ -27,10 +28,9 @@ def feature
#
# @api public
def steps
- step_definitions = step_definitions_klass.new
- @steps ||=(feature.background_steps + @scenario.steps).map do |step|
- StepRunner.new(step, step_definitions)
- end
+ all_steps = (feature.background_steps + @scenario.steps)
+ context = step_definitions_klass.new
+ @steps ||= StepCollection.new(all_steps, context)
end
def step_definitions_klass
@@ -66,17 +66,11 @@ def hooks
end
def run_scenario_steps
- previous_step_success = true
- steps.each do |step|
- step.run(previous_step_success)
- previous_step_success = step.success?
- end
+ steps.run
end
def success?
- steps.all? do |step|
- step.success?
- end
+ steps.success?
end
end
end
@@ -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

0 comments on commit 913db70

Please sign in to comment.