Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The default behaviour for non-rcov rake runs is 'in-process'

Previously, we shelled out via system calls to ruby, now we just
require the runner, disable the at exit hook, and the suite progresses
as normal.
  • Loading branch information...
commit 4594bc27174c84b01d653b42f1e9a454ccf5f63c 1 parent d72db59
Chad Humphries and Chris Redinger authored
View
41 lib/rspec/core/rake_task.rb
@@ -62,21 +62,30 @@ def define # :nodoc:
if files_to_run.empty?
puts "No examples matching #{pattern} could be found"
else
- cmd_parts = [
- runner,
- runner_options,
- '-Ilib',
- '-Ispec'
- ]
+ cmd_parts = [ '-Ilib', '-Ispec' ]
cmd_parts << "-w" if warning
- cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
- cmd = cmd_parts.join(" ")
- puts cmd if verbose
- unless system(cmd)
- STDERR.puts failure_message if failure_message
- raise("Command #{cmd} failed") if fail_on_error
+ if rcov
+ command_to_run = rcov_command(cmd_parts)
+ command_to_run.inspect if verbose
+
+ unless system(command_to_run)
+ STDERR.puts failure_message if failure_message
+ raise("#{command_to_run} failed") if fail_on_error
+ end
+ else
+ cmd_parts.concat(files_to_run)
+ puts cmd.inspect if verbose
+
+ require 'rspec/core'
+ RSpec::Core::Runner.disable_at_exit_hook!
+
+ unless RSpec::Core::Runner.run(cmd_parts, $stderr, $stdout)
+ STDERR.puts failure_message if failure_message
+ raise("RSpec::Core::Runner.run with args #{cmd_parts.inspect} failed") if fail_on_error
+ end
end
+
end
end
end
@@ -89,6 +98,14 @@ def files_to_run # :nodoc:
end
private
+
+ def rcov_command(cmd_parts)
+ cmd_parts.unshift runner_options
+ cmd_parts.unshift runner
+ cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
+ cmd_parts.join(" ")
+ end
+
def runner
rcov ? rcov_path : RUBY
end
View
10 lib/rspec/core/runner.rb
@@ -4,12 +4,20 @@ module RSpec
module Core
class Runner
+ def self.at_exit_hook_disabled?
+ @no_at_exit_hook ||= false
+ end
+
+ def self.disable_at_exit_hook!
+ @no_at_exit_hook = true
+ end
+
def self.installed_at_exit?
@installed_at_exit ||= false
end
def self.autorun
- return if installed_at_exit? || running_in_drb?
+ return if at_exit_hook_disabled? || installed_at_exit? || running_in_drb?
@installed_at_exit = true
at_exit { run(ARGV, $stderr, $stdout) ? exit(0) : exit(1) }
end
View
2  spec/rspec/core/runner_spec.rb
@@ -6,6 +6,7 @@ module RSpec::Core
it 'sets an at_exit hook if none is already set' do
RSpec::Core::Runner.stub(:installed_at_exit?).and_return(false)
RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
+ RSpec::Core::Runner.stub(:at_exit_hook_disabled?).and_return(false)
RSpec::Core::Runner.should_receive(:at_exit)
RSpec::Core::Runner.autorun
end
@@ -13,6 +14,7 @@ module RSpec::Core
it 'does not set the at_exit hook if it is already set' do
RSpec::Core::Runner.stub(:installed_at_exit?).and_return(true)
RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
+ RSpec::Core::Runner.stub(:at_exit_hook_disabled?).and_return(false)
RSpec::Core::Runner.should_receive(:at_exit).never
RSpec::Core::Runner.autorun
end
Please sign in to comment.
Something went wrong with that request. Please try again.