Browse files

Delay the loading of DRB.

- Most of the time users don't use DRB. This'll speed up the start time a bit
  by not unnecessarily loading it when it's not used.
- Apparently jruby 1.7.0-preview1 loads the delegate library when DRB is loaded [1][2].
  This causes expectations on delegate objects to fail because `should` never gets added
  to them. By delaying when delegate gets loaded, it allows a user to load
  `rspec/expectations` and then `delegate` and ensure it works.

[1] rspec/rspec-expectations#148 (comment)
[2] The backtrace at the point delegate is loaded:
/Users/myron/.rvm/rubies/jruby-head/lib/ruby/1.9/drb/drb.rb:1:in `require'
/Users/myron/.rvm/rubies/jruby-head/lib/ruby/1.9/drb/drb.rb:1:in `(root)'
/Users/myron/.rvm/rubies/jruby-head/lib/ruby/1.9/drb/drb.rb:57:in `require'
/Users/myron/.rvm/rubies/jruby-head/lib/ruby/1.9/drb/drb.rb:57:in `(root)'
/Users/myron/.rvm/gems/jruby-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:1:in `require'
/Users/myron/.rvm/gems/jruby-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:1:in `(root)'
/Users/myron/.rvm/gems/jruby-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:1:in `(root)'
file:/Users/myron/.rvm/rubies/jruby-head/lib/jruby.jar!/jruby/kernel19/kernel.rb:1:in `(root)'
file:/Users/myron/.rvm/rubies/jruby-head/lib/jruby.jar!/jruby/kernel19/kernel.rb:19:in `require'
file:/Users/myron/.rvm/rubies/jruby-head/lib/jruby.jar!/jruby/kernel19/kernel.rb:19:in `require_relative'
/Users/myron/.rvm/gems/jruby-head/gems/rspec-core-2.10.1/lib/rspec/core.rb:4:in `require'
/Users/myron/.rvm/gems/jruby-head/gems/rspec-core-2.10.1/lib/rspec/core.rb:4:in `require_rspec'
/Users/myron/.rvm/gems/jruby-head/bin/rspec:23:in `load'
/Users/myron/.rvm/gems/jruby-head/bin/rspec:23:in `(root)'
  • Loading branch information...
1 parent 4feeec6 commit 3646611ec6b2de10c57b806abc40083fa29ceae6 @myronmarston myronmarston committed Jun 6, 2012
View
2 lib/rspec/core.rb
@@ -31,10 +31,8 @@ def require_rspec(path)
require_rspec 'core/configuration'
require_rspec 'core/project_initializer'
require_rspec 'core/option_parser'
-require_rspec 'core/drb_options'
require_rspec 'core/configuration_options'
require_rspec 'core/command_line'
-require_rspec 'core/drb_command_line'
require_rspec 'core/runner'
require_rspec 'core/example'
require_rspec 'core/shared_example_group'
View
3 lib/rspec/core/drb_command_line.rb
@@ -1,3 +1,6 @@
+require 'drb/drb'
+require 'rspec/core/drb_options'
+
module RSpec
module Core
class DRbCommandLine
View
4 lib/rspec/core/runner.rb
@@ -1,5 +1,3 @@
-require 'drb/drb'
-
module RSpec
module Core
class Runner
@@ -25,6 +23,7 @@ def self.installed_at_exit?
end
def self.running_in_drb?
+ defined?(DRb) &&
(DRb.current_server rescue false) &&
DRb.current_server.uri =~ /druby\:\/\/127.0.0.1\:/
end
@@ -59,6 +58,7 @@ def self.run(args, err=$stderr, out=$stdout)
options.parse_options
if options.options[:drb]
+ require 'rspec/core/drb_command_line'
begin
DRbCommandLine.new(options).run(err, out)
rescue DRb::DRbConnError
View
1 spec/rspec/core/drb_command_line_spec.rb
@@ -1,4 +1,5 @@
require "spec_helper"
+require 'rspec/core/drb_command_line'
describe "::DRbCommandLine", :type => :drb, :unless => RUBY_PLATFORM == 'java' do
let(:config) { RSpec::Core::Configuration.new }
View
1 spec/rspec/core/drb_options_spec.rb
@@ -1,4 +1,5 @@
require "spec_helper"
+require 'rspec/core/drb_options'
describe RSpec::Core::DrbOptions, :fakefs do
include ConfigOptionsHelper

0 comments on commit 3646611

Please sign in to comment.