当使用 RSpec 测试继承另一个继承赛璐珞的 B 类的 A 类时,我试图为 A 类中的一个方法的调用设置一个期望,该方法会覆盖其在 B 类上的实现。
这是一个示例代码:
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
此测试生成失败:
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)>'
我可以让 Rspec 测试我们正在调用覆盖方法,因此,让这个测试通过吗?