Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Delay the loading of DRB. #629

Merged
merged 1 commit into from

3 participants

@myronmarston
Owner

@dchelimsky -- can you code review this before I merge it in? I've never used rspec's DRB option before (and couldn't figure out how to get it to work in few minutes of futzing with it).

@myronmarston myronmarston 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)'
3646611
@travisbot

This pull request passes (merged 3646611 into 4feeec6).

@dchelimsky
Owner

@myronmarston no, we don't have any automated scenarios for this, but I checked it manually and it works fine. Curious as to what led you to this?

@myronmarston myronmarston merged commit 9a79082 into from
@myronmarston

@myronmarston no, we don't have any automated scenarios for this, but I checked it manually and it works fine. Curious as to what led you to this?

I put a fair bit of detail in the commit message (did you see that?), but to recap: @jeremyevans noticed an rspec regression in his sequel specs: before rspec 2.10, expectations on delegate objects worked. The new expect syntax is the official fix moving forward, but he's kept his test suite passing against rspec 1.3+, and wanted a work-around. The work around I came up with is to manually require rspec/expectations before the delegate stdlib gets loaded (which ensures that should is defined on Kernel before delegate selectively includes methods defined on kernel). The work around worked fine except on jruby 1.7.0-preview1. It loads delegate as part of its DRB implementation, and thus, loading rspec-core on that version loads delegate before users have a chance to load rspec-expectations. Delaying the loading of DRB fixes this, and also should make the loading of rspec a tiny bit faster for the 99% of users who don't use DRB when running rspec.

In general, I think we should favor lazily loading optional dependencies like DRB, as a means to reduce bloat and improve startup time.

@dchelimsky
Owner

@myronmarston I hadn't seen the commit message since github doesn't display it in the diff for the pull. Makes perfect sense all around, including lazy-loading DRB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 6, 2012
  1. @myronmarston

    Delay the loading of DRB.

    myronmarston authored
    - 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)'
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.