【问题标题】:RSpec: Using view.should_receive with subjectRSpec:将 view.should_receive 与主题一起使用
【发布时间】:2012-06-07 23:56:26
【问题描述】:

任何想法为什么会这样:

it {view.should_receive(:update_method)}

但这不是?:

subject { view }
it { should_receive(:update_method) }

其他一切都一样。我收到此错误:

Failure/Error: it {should_receive(:update_method) 
(#<RSpec::Core::ExampleGroup::Nested_1:0x7faf27602d58>).update_method
    expected: 1 time
    received: 0 times 

但我不知道 RSpec::Core::ExampleGroup::Nested.... 指的是什么。有什么想法吗?

提前致谢!

【问题讨论】:

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


    【解决方案1】:

    这是 24 小时内第二次出现这种情况。有什么东西在空中。解释见https://github.com/rspec/rspec-mocks/issues/148

    【讨论】:

    • 谢谢。这样就搞清楚了。在我有机会滥用后钩太长时间之前被重定向是件好事。我查看了模拟期望,但无法真正掌握 should_receive 与其他应该期望之间的区别。对此有任何快速指示吗?再次感谢并保重!
    • 什么是“示例后清理”的好例子。我想不出何时正确使用后钩。回滚数据库修改?再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 2014-11-21
    • 1970-01-01
    • 2019-11-27
    • 2020-01-20
    相关资源
    最近更新 更多