Permalink
Browse files

Revert "Remove at_exit hook and rspec/autorun"

This reverts commit c6f7806.

- needed to revert because this broke the rake task with rcov
  • Loading branch information...
1 parent ce75651 commit 5cebc85b11d0de58a33b7913351a1feee2a12025 @dchelimsky dchelimsky committed Sep 23, 2010
Showing with 42 additions and 3 deletions.
  1. +1 −2 bin/rspec
  2. +2 −0 lib/rspec/autorun.rb
  3. +1 −0 lib/rspec/core/example_group.rb
  4. +20 −1 lib/rspec/core/runner.rb
  5. +18 −0 spec/rspec/core/runner_spec.rb
View
@@ -1,3 +1,2 @@
#!/usr/bin/env ruby
-require 'rspec/core'
-exit RSpec::Core::Runner.run(ARGV, $stderr, $stdout)
+require 'rspec/autorun'
View
@@ -0,0 +1,2 @@
+require 'rspec/core'
+RSpec::Core::Runner.autorun
@@ -20,6 +20,7 @@ def self.world
end
def self.inherited(klass)
+ RSpec::Core::Runner.autorun
world.example_groups << klass if klass.top_level?
end
View
@@ -4,8 +4,27 @@ module RSpec
module Core
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!
- 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
def self.trap_interrupt
@@ -2,6 +2,24 @@
module RSpec::Core
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
context "with --drb or -X" do
before(:each) do

0 comments on commit 5cebc85

Please sign in to comment.