Skip to content

Commit

Permalink
The default behaviour for non-rcov rake runs is 'in-process'
Browse files Browse the repository at this point in the history
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
Chad Humphries and Chris Redinger committed Jun 18, 2010
1 parent d72db59 commit 4594bc2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
41 changes: 29 additions & 12 deletions lib/rspec/core/rake_task.rb
Expand Up @@ -62,21 +62,30 @@ def define # :nodoc:
if files_to_run.empty? if files_to_run.empty?
puts "No examples matching #{pattern} could be found" puts "No examples matching #{pattern} could be found"
else else
cmd_parts = [ cmd_parts = [ '-Ilib', '-Ispec' ]
runner,
runner_options,
'-Ilib',
'-Ispec'
]
cmd_parts << "-w" if warning cmd_parts << "-w" if warning
cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
cmd = cmd_parts.join(" ")
puts cmd if verbose


unless system(cmd) if rcov
STDERR.puts failure_message if failure_message command_to_run = rcov_command(cmd_parts)
raise("Command #{cmd} failed") if fail_on_error 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
end end
end end
Expand All @@ -89,6 +98,14 @@ def files_to_run # :nodoc:
end end


private 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 def runner
rcov ? rcov_path : RUBY rcov ? rcov_path : RUBY
end end
Expand Down
10 changes: 9 additions & 1 deletion lib/rspec/core/runner.rb
Expand Up @@ -4,12 +4,20 @@ module RSpec
module Core module Core
class Runner 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? def self.installed_at_exit?
@installed_at_exit ||= false @installed_at_exit ||= false
end end


def self.autorun 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 @installed_at_exit = true
at_exit { run(ARGV, $stderr, $stdout) ? exit(0) : exit(1) } at_exit { run(ARGV, $stderr, $stdout) ? exit(0) : exit(1) }
end end
Expand Down
2 changes: 2 additions & 0 deletions spec/rspec/core/runner_spec.rb
Expand Up @@ -6,13 +6,15 @@ module RSpec::Core
it 'sets an at_exit hook if none is already set' do 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(:installed_at_exit?).and_return(false)
RSpec::Core::Runner.stub(:running_in_drb?).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.should_receive(:at_exit)
RSpec::Core::Runner.autorun RSpec::Core::Runner.autorun
end end


it 'does not set the at_exit hook if it is already set' do 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(:installed_at_exit?).and_return(true)
RSpec::Core::Runner.stub(:running_in_drb?).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).never RSpec::Core::Runner.should_receive(:at_exit).never
RSpec::Core::Runner.autorun RSpec::Core::Runner.autorun
end end
Expand Down

0 comments on commit 4594bc2

Please sign in to comment.