expect_to_receive无效

时间:2014-07-15 14:55:30

标签: ruby-on-rails ruby rspec rspec-rails

我试图使用expect_to_receive rspec期望,但没有任何运气。我的控制器规格文件看起来像这样:

it 'resolves an end behaviour' do
  expect_any_instance_of(Job).to receive(:resolve_end_behaviour)

  post :callback, @params
end

我的控制器方法:

def callback
  @video = JobVideo.find(params['body']['id'].to_i)
  if !@video.is_ready
    @video.job.resolve_end_behaviour
    @video.update_attribute(:is_ready, true)
  end

  render json: { success: true }
end

正在运行rspec给了我:

Exactly one instance should have received the following message(s) but didn't: resolve_end_behaviour

我确定调用此方法导致is_ready列更新。任何人都可以给我任何线索,说明为什么会发生这种情况,我该怎么办呢?提前谢谢。

ENV:

  • rails 4
  • rspec 3

1 个答案:

答案 0 :(得分:1)

您的测试期望使用两个参数调用resolve_end_behaviour,您在没有参数的情况下调用它。