Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be_* predicate gives wrong results when requiring delegate before rspec #471

Closed
eregon opened this issue Oct 8, 2011 · 0 comments
Closed

Comments

@eregon
Copy link
Contributor

eregon commented Oct 8, 2011

This bug is really weird, I searched what caused it during a few hours.

It is probably similar to: http://rubyforge.org/tracker/?func=detail&atid=3149&aid=11526&group_id=797
I tried to find more info about it but did not succeed.
Could you give me access to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/48-11526-rspec-fails-to-dynamically-bind-delegateclass-methods#ticket-48-2 ?

Here is a small reproducing example:

# compare `RUBYOPT=-rdelegate rspec spec.rb` and `rspec spec.rb`
require 'delegate'

class Immediate
  def cached?
    false
  end
end

class Cached < SimpleDelegator
  def initialize(d)
    super d
  end

  def cached?
    true
  end
end

describe 'A' do
  subject{ Cached.new(Immediate.new) }

  it 'b' do
    p subject.cached? # => true
    subject.should be_cached
  end
end

The example fails only when the 'delegate' library is required before 'rspec', on 1.9 (jruby and mri).
You can also observe this problem by running the specs of rspec-expectations:

RUBYOPT=-rdelegate rake spec

The "arbitrary predicate with DelegateClass"/"accesses methods defined in the delegating class (LH[#48])" (spec/rspec/matchers/be_spec.rb#412) example is indeed testing similar behavior.

I guess the problem mainly lies in lib/delegate.rb which changed a lot from 1.8 on 1.9, notably by using BasicObject. There is some dark magic there, like Kernel.dup.

Until the problem is found, I think RSpec should emit a warning (or abort) when 'delegate' is required before 'rspec' to help users hitting this bug.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants