Skip to content

Commit

Permalink
Better matching of scenario line
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephHalter committed Nov 27, 2011
1 parent c8f9cbf commit ce420ff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/spinach/runner/feature_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ def run
private

def run_scenarios!
scenarios.each do |scenario|
if !@scenario_line || (scenario.line == @scenario_line)
scenarios.each_with_index do |scenario, current_scenario_index|
if match(current_scenario_index)
success = ScenarioRunner.new(scenario).run
@failed = true unless success
end
end
end

def match(current_scenario_index)
return true unless @line
return false if @line<scenarios[current_scenario_index].line
next_scenario = scenarios[current_scenario_index+1]
!next_scenario || @line<next_scenario.line
end

def undefined_steps!
Spinach.hooks.run_on_undefined_feature @feature
@failed = true
Expand Down
32 changes: 32 additions & 0 deletions test/spinach/runner/feature_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,37 @@
subject.run.must_equal false
end
end

describe "when a line is given" do
before do
@feature = stub('feature', name: 'Feature')
Spinach.stubs(:find_step_definitions).returns(true)
@scenarios = [
scenario = stub(line: 4),
another_scenario = stub(line: 12)
]
@feature.stubs(:scenarios).returns @scenarios
end
it "runs exactly matching scenario" do
Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[1]).returns stub(run: true)
@runner = Spinach::Runner::FeatureRunner.new(@feature, "12")
@runner.run
end
it "runs no scenario and returns false" do
Spinach::Runner::ScenarioRunner.expects(:new).never
@runner = Spinach::Runner::FeatureRunner.new(@feature, "3")
@runner.run
end
it "runs matching scenario" do
Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[0]).returns stub(run: true)
@runner = Spinach::Runner::FeatureRunner.new(@feature, "8")
@runner.run
end
it "runs last scenario" do
Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[1]).returns stub(run: true)
@runner = Spinach::Runner::FeatureRunner.new(@feature, "15")
@runner.run
end
end
end
end

0 comments on commit ce420ff

Please sign in to comment.