Skip to content

Commit

Permalink
Merge pull request #25 from codegram/feature/exit_code
Browse files Browse the repository at this point in the history
Feature/exit code
  • Loading branch information
josepjaume committed Oct 1, 2011
2 parents 68fe94f + 7e688c0 commit 368fd54
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bin/spinach
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ rescue LoadError
require_relative '../lib/spinach'
end

Spinach::Cli.new(ARGV).run
exit Spinach::Cli.new(ARGV).run
14 changes: 14 additions & 0 deletions features/exit_status.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Exit status
In order to receive a standard exit code
As a developer
I want spinach to return exit status properly

Scenario: It succeeds
Given I have a feature that has no error or failure
When I run it
Then the exit status should be 0

Scenario: It fails
Given I have a feature that has a failure
When I run it
Then the exit status should be 1
50 changes: 50 additions & 0 deletions features/steps/exit_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'aruba/api'

Feature "Exit status" do
include Integration::SpinachRunner

Given "I have a feature that has no error or failure" do
write_file('features/success_feature.feature',
'Feature: A success feature
Scenario: This is scenario will succeed
Then I succeed
')
write_file('features/steps/success_feature.rb',
'Feature "A success feature" do
Then "I succeed" do
end
end')
@feature = "features/success_feature.feature"
end

Given "I have a feature that has a failure" do
write_file('features/failure_feature.feature',
'Feature: A failure feature
Scenario: This is scenario will fail
Then I fail
')
write_file('features/steps/failure_feature.rb',
'Feature "A failure feature" do
Then "I fail" do
true.must_equal false
end
end')
@feature = "features/failure_feature.feature"
end

When "I run it" do
run_feature @feature
all_stdout # Hack to get a correct exit status
end

Then "the exit status should be 0" do
last_exit_status.must_equal 0
end

Then "the exit status should be 1" do
last_exit_status.must_equal 1
end

end
5 changes: 3 additions & 2 deletions lib/spinach/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def run
require_dependencies

filenames.each do |filename|
Feature.new(filename, reporter).run
success = Feature.new(filename, reporter).run
@failed = true unless success
end
reporter.end

@failed ? false : true
end

# Requires step definitions and support files
Expand Down
3 changes: 3 additions & 0 deletions lib/spinach/runner/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def run

unless failures.length.zero?
reporter.error_summary(failures)
return false
else
return true
end
end

Expand Down
14 changes: 14 additions & 0 deletions test/spinach/runner/feature_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
@feature.run
end

it "returns true if the execution succeeds" do
@feature.stubs(reporter: stub_everything)
Spinach::Runner::Scenario.any_instance.
expects(run: nil).times(3)
@feature.run.must_equal true
end

it "returns false if the execution fails" do
@feature.stubs(reporter: stub_everything)
Spinach::Runner::Scenario.any_instance.
expects(run: stub_everything).times(3)
@feature.run.must_equal false
end

it 'calls only the given scenario' do
@filename = 'feature/a_cool_feature.feature:12'
@feature = Spinach::Runner::Feature.new(@filename, @reporter)
Expand Down
15 changes: 11 additions & 4 deletions test/spinach/runner/scenario_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@scenario.run
end

describe 'rescues exceptions' do
describe 'when throwing exceptions' do
it 'rescues a MiniTest::Assertion' do
@feature.expects(:execute_step).raises(MiniTest::Assertion)
@reporter.expects(:step).with(anything, anything, :failure)
Expand All @@ -61,10 +61,17 @@
@scenario.run
end

it 'runs a step' do
@reporter.expects(:step).with(anything, anything, :success).times(3)
@scenario.run
it "returns an failure" do
@feature.expects(:execute_step).raises(MiniTest::Assertion)
@scenario.run.wont_equal nil
end

end

it 'runs a step' do
@reporter.expects(:step).with(anything, anything, :success).times(3)
@scenario.run.must_equal nil
end

end
end
13 changes: 10 additions & 3 deletions test/spinach/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@
end
end
describe "#run" do
it "instantiates a new Feature and runs it with every file" do
feature = stub(run: nil)
before do
@feature = stub
@runner.stubs(reporter: stub_everything)
@filenames.each do |filename|
Spinach::Runner::Feature.expects(:new).
with(filename, anything).
returns(feature)
returns(@feature)
end
end
it "instantiates a new Feature and runs it with every file" do
@feature.stubs(run: true)
@runner.run.must_equal true
end
it "returns false if it fails" do
@feature.stubs(run: false)
@runner.run
end
end
Expand Down

0 comments on commit 368fd54

Please sign in to comment.