celluloid: Stubbing actor internals doesn't work


require 'celluloid'

class A
  include Celluloid

  def b
    c
  end

  def c
    "Hello"
  end
end

describe A do
  it "should allow mocking" do
    subject.should_receive(:c).twice.and_return "World"
    subject.c.should == "World"
    subject.b.should == "World"
  end
end

In this instance, it can be seen that from outside of the A instance, calling the stubbed method works, but it does not internally. Removing the Celluloid include causes the test to pass.

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 23 (17 by maintainers)

Commits related to this issue

Most upvoted comments

@tarcieri: Correct. RSpec is stubbing the Celluloid::Actor object, and so calls that go via that hit the stub and not the delegate. When the delegate makes the method call, however, it knows nothing of the Actor, and thus the stub, and uses the implementation as it’s written. It’s a definite scope issue, I’m just not sure how to deal with it. It’s not as if we can have the delegate make any calls on self via the Actor (or can we?).

@dchelimsky: Mocha behaves the same as RSpec. The bug is most definitely in Celluloid.