RSpec expecting call to overridden method of Celluloid base class

178 views Asked by At

When using RSpec to test class A that inherits another class B that inherits Celluloid, I am trying to set an expectation for a call of a method in class A that overrides its implementation on class B.

Here's an example code:

require 'celluloid'

class B
  include Celluloid

  def method1
  end
end

class A < B
  def initialize
  end
  def method1
    puts "Called!"
  end
  def method2
    method1
  end
end
context "test inherited" do
  before(:each) do
    @instance = A.new
  end

  it "should call metod1 on calling method2" do
    expect(@instance).to receive(:method1)

    @instance.method2
  end
end

This test generates the failure:

  1) test inherited should call metod1 on calling method2
     Failure/Error: expect(@instance).to receive(:method1)
     
       (#<Celluloid::CellProxy(A:0x3fc733109b9c)>).method1(*(any args))
           expected: 1 time with any arguments
           received: 0 times with any arguments
     # ./spec/api/sandbox.spec:13:in `block (2 levels) in <top (required)>'

can I get the Rspec to test that we're calling the overriding method, and so, make this test pass?

0

There are 0 answers