Skip to content

Commit

Permalink
Fix the bug
Browse files Browse the repository at this point in the history
When spinach runs a pending step. It will halt the whole scenario and
move onto the next scenario.
  • Loading branch information
ywen committed Jun 17, 2013
1 parent cc1dc8b commit 64317a7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion features/pending_steps.feature
Expand Up @@ -7,4 +7,3 @@ Feature: Pending steps
Given I have a feature that has a pending step
When I run the feature
Then the test stops at the pending step and reported as such

6 changes: 4 additions & 2 deletions features/steps/pending_steps.rb
Expand Up @@ -2,14 +2,16 @@ class Spinach::Features::PendingSteps < Spinach::FeatureSteps
include Integration::SpinachRunner

step 'I have a feature that has a pending step' do
@feature = Integration::FeatureGenerator.pending_feature
@feature = Integration::FeatureGenerator.pending_feature_with_multiple_scenario
end

step 'I run the feature' do
run_feature @feature
end

step 'the test stops at the pending step and reported as such' do
@stdout.must_match("(0) Successful")
@stdout.must_match("(1) Successful")
@stdout.must_match("(0) Failed")
@stdout.must_match("(1) Pending")
end
end
18 changes: 12 additions & 6 deletions features/support/feature_generator.rb
Expand Up @@ -22,9 +22,10 @@ def success_feature
# The feature file name
#
# @api private
def pending_feature
steps = pending_step_class_str + pending_step + success_step + "\nend"
write_feature 'features/success_feature.feature', pending_feature_str,
def pending_feature_with_multiple_scenario
feature_str = pending_feature_str + "\n" + success_scenario
steps = pending_step_class_str + pending_step + "\n" + failure_step_definition + success_step + "\nend"
write_feature 'features/success_feature.feature', feature_str,
'features/steps/success_feature.rb', steps
end

Expand Down Expand Up @@ -77,9 +78,14 @@ def write_feature(feature_file, feature, step_file, steps)
end

def failure_step
'class AFailureFeature < Spinach::FeatureSteps
%Q|class AFailureFeature < Spinach::FeatureSteps
feature "A failure feature"
Then "I fail" do
%{failure_step_definition}
|
end

def failure_step_definition
'Then "I fail" do
true.must_equal false
end'
end
Expand All @@ -88,7 +94,7 @@ def pending_feature_str
"Feature: A pending feature
Scenario: This is scenario will be pending
When this is a pending step
Then I succeed"
Then I fail"
end

def success_scenario
Expand Down
3 changes: 2 additions & 1 deletion lib/spinach/runner/scenario_runner.rb
Expand Up @@ -51,7 +51,7 @@ def run
steps.each do |step|
Spinach.hooks.run_before_step step, step_definitions

if @exception
if @exception || @has_pending_step
Spinach.hooks.run_on_skipped_step step, step_definitions
else
run_step(step)
Expand Down Expand Up @@ -84,6 +84,7 @@ def run_step(step)
Spinach.hooks.run_on_undefined_step step, @exception, step_definitions
rescue Spinach::StepPendingException => e
e.step = step
@has_pending_step = true
Spinach.hooks.run_on_pending_step step, e
rescue Exception => e
@exception = e
Expand Down
5 changes: 5 additions & 0 deletions test/spinach/runner/scenario_runner_test.rb
Expand Up @@ -154,6 +154,11 @@ class Runner
subject.instance_variable_get(:@exception).must_be_kind_of(NilClass)
end

it 'sets the has_pending_step' do
subject.run_step(@step)
subject.instance_variable_get(:@has_pending_step).must_equal(true)
end

it 'runs the pending hooks' do
Spinach.hooks.expects(:run_on_pending_step).with(@step, kind_of(Spinach::StepPendingException))
subject.run_step(@step)
Expand Down

0 comments on commit 64317a7

Please sign in to comment.