Skip to content

Commit

Permalink
Revert "Remove at_exit hook and rspec/autorun"
Browse files Browse the repository at this point in the history
This reverts commit c6f7806.

- needed to revert because this broke the rake task with rcov
  • Loading branch information
dchelimsky committed Sep 23, 2010
1 parent ce75651 commit 5cebc85
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
3 changes: 1 addition & 2 deletions bin/rspec
@@ -1,3 +1,2 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'rspec/core' require 'rspec/autorun'
exit RSpec::Core::Runner.run(ARGV, $stderr, $stdout)
2 changes: 2 additions & 0 deletions lib/rspec/autorun.rb
@@ -0,0 +1,2 @@
require 'rspec/core'
RSpec::Core::Runner.autorun
1 change: 1 addition & 0 deletions lib/rspec/core/example_group.rb
Expand Up @@ -20,6 +20,7 @@ def self.world
end end


def self.inherited(klass) def self.inherited(klass)
RSpec::Core::Runner.autorun
world.example_groups << klass if klass.top_level? world.example_groups << klass if klass.top_level?
end end


Expand Down
21 changes: 20 additions & 1 deletion lib/rspec/core/runner.rb
Expand Up @@ -4,8 +4,27 @@ module RSpec
module Core module Core
class Runner class Runner


def self.autorun
return if autorun_disabled? || installed_at_exit? || running_in_drb?
@installed_at_exit = true
at_exit { run(ARGV, $stderr, $stdout) ? exit(0) : exit(1) }
end

def self.autorun_disabled?
@autorun_disabled ||= false
end

def self.disable_autorun! def self.disable_autorun!
RSpec.deprecate("disable_autorun!") @autorun_disabled = true
end

def self.installed_at_exit?
@installed_at_exit ||= false
end

def self.running_in_drb?
(DRb.current_server rescue false) &&
!!((DRb.current_server.uri) =~ /druby\:\/\/127.0.0.1\:/)
end end


def self.trap_interrupt def self.trap_interrupt
Expand Down
18 changes: 18 additions & 0 deletions spec/rspec/core/runner_spec.rb
Expand Up @@ -2,6 +2,24 @@


module RSpec::Core module RSpec::Core
describe Runner do describe Runner do
describe 'at_exit' 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(: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

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
end

describe "#run" do describe "#run" do
context "with --drb or -X" do context "with --drb or -X" do
before(:each) do before(:each) do
Expand Down

0 comments on commit 5cebc85

Please sign in to comment.