Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit ad53e7f

Browse files
committed
Fix RSpec::Core::RakeTask#failure_message.
`system` returns a boolean value to indicate success/failure, but the use of `failure_message` was in a `rescue` block that never got executed. It appears this has been broken since ea70e4e. Before that commit, we used `Rake::FileUtilsExt#ruby`, which does indicate failure by raising an error (and thus the `rescue` was correct). In ea70e4e, we switched to using `system` and the rescue was left in place but never got hit anymore. The lack of test coverage here is why we never noticed, so I addressed that as well.
1 parent 4a61665 commit ad53e7f

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Bug Fixes:
3232
* Handle invalid UTF-8 strings within exception methods. (Benjamin Fleischer, #1760)
3333
* Fix Rake Task quoting of file names with quotes to work properly on
3434
Windows. (Myron Marston, #1887)
35+
* Fix `RSpec::Core::RakeTask#failure_message` so that it gets printed
36+
when the task failed. (Myron Marston, #1905)
3537

3638
### 3.2.2 / 2015-03-11
3739
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.2.1...v3.2.2)

lib/rspec/core/rake_task.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,12 @@ def initialize(*args, &task_block)
6363
# @private
6464
def run_task(verbose)
6565
command = spec_command
66+
puts command if verbose
6667

67-
begin
68-
puts command if verbose
69-
success = system(command)
70-
rescue
71-
puts failure_message if failure_message
72-
end
73-
74-
return unless fail_on_error && !success
68+
return if system(command)
69+
puts failure_message if failure_message
7570

71+
return unless fail_on_error
7672
$stderr.puts "#{command} failed" if verbose
7773
exit $?.exitstatus
7874
end

spec/rspec/core/rake_task_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ def spec_command
8080
end
8181
end
8282

83+
context "when `failure_message` is configured" do
84+
before do
85+
allow(task).to receive(:exit)
86+
task.failure_message = "Bad news"
87+
end
88+
89+
it 'prints it if the RSpec run failed' do
90+
task.ruby_opts = '-e "exit(1);" ;#'
91+
expect { task.run_task false }.to output(/Bad news/).to_stdout
92+
end
93+
94+
it 'does not print it if the RSpec run succeeded' do
95+
task.ruby_opts = '-e "exit(0);" ;#'
96+
expect { task.run_task false }.not_to output(/Bad/).to_stdout
97+
end
98+
end
99+
83100
context 'with custom exit status' do
84101
def silence_output(&block)
85102
expect(&block).to output(anything).to_stdout.and output(anything).to_stderr

0 commit comments

Comments
 (0)