不太清楚这里发生了什么。我正在从我的另一个项目中转移一些代码,突然之间,以前的相同规范在新项目中产生了错误。所有错误似乎都围绕调用存根方法。这是一个示例测试:
it "retrieves active workers from Redis" do
@monitor.should_receive(:monitor_running?).and_return(false)
REDIS.should_receive( :smembers ).with( 'leaderboard-workers' ).and_return( [] )
@monitor.perform
end
这行得通。但是,如果我将第一条测试线切换为:
@monitor.stub(:monitor_running?).and_return(false)
我最终得到以下错误:
1) LeaderboardMonitor#perform retrieves active workers from Redis
Failure/Error: @monitor.stub(:monitor_running?).and_return(false)
Mocha::ExpectationError:
unexpected invocation: #<Mock:0x7fcc18c8bab8>.and_return(false)
satisfied expectations:
- allowed any number of times, not yet invoked: #<Mock:0x7fcc18c8bab8>.monitor_running?(any_parameters)
# ./spec/workers/leaderboards/leaderboard_monitor_spec.rb:58:in `block (3 levels) in <top (required)>'
我不太确定这里发生了什么。这是 Mocha 覆盖存根方法的问题吗?我该如何解决这个问题?!?!?