Skip to content

Commit

Permalink
Merge pull request #1196 from rspec/correct_rake_task_exit_code
Browse files Browse the repository at this point in the history
rspec command exits with non zero status, 0 failures
  • Loading branch information
JonRowe committed Nov 28, 2013
2 parents 5ceba6b + 92c7884 commit 24bde68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rspec/core/rake_task.rb
Expand Up @@ -97,7 +97,10 @@ def run_task(verbose)
rescue
puts failure_message if failure_message
end
abort("#{command} failed") if fail_on_error unless success
if fail_on_error && !success
$stderr.puts "#{command} failed"
exit $?.exitstatus
end
end

private
Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/core/rake_task_spec.rb
Expand Up @@ -53,6 +53,17 @@ def spec_command
end
end

context 'with custom exit status' do
it 'returns the correct status on exit' do
with_isolated_stderr do
expect($stderr).to receive(:puts) { |cmd| expect(cmd).to match /-e "exit\(2\);".* failed/ }
expect(task).to receive(:exit).with(2)
task.ruby_opts = '-e "exit(2);" ;#'
task.run_task false
end
end
end

def specify_consistent_ordering_of_files_to_run(pattern, task)
orderings = [
%w[ a/1.rb a/2.rb a/3.rb ],
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -122,13 +122,23 @@ def without_env_vars(*vars)
end
end

module StdErrIsolation
def with_isolated_stderr
original = $stderr
$stderr = StringIO.new
yield
$stderr = original
end
end

require 'rspec/support/spec'

RSpec.configure do |c|
# structural
c.alias_it_behaves_like_to 'it_has_behavior'
c.around {|example| Sandboxing.sandboxed { example.run }}
c.include(RSpecHelpers)
c.include(StdErrIsolation)
c.include Aruba::Api, :example_group => {
:file_path => /spec\/command_line/
}
Expand Down

0 comments on commit 24bde68

Please sign in to comment.