【问题标题】:around_filter stubbing in Rspec?在 Rspec 中的 around_filter 存根?
【发布时间】:2014-05-16 06:08:21
【问题描述】:

您好,我正在尝试使用 rspec 中的以下源代码在控制器中存根始终返回 true 的 around_filter 方法

before(:each) do
  controller.stub(:catch_exceptions).and_return(true)
end
after(:each) do
  controller.stub(:catch_exceptions).and_return(true)
end

但它失败了。当我将特定方法更改为 before_filter 时,它可以正常工作吗?谁能帮帮我?

【问题讨论】:

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


    【解决方案1】:

    要正确地存根around_filter,您应该yield 以使其余操作正常工作,否则,您只是在存根整个操作...

    controller.stub(:catch_exceptions).and_yield
    

    【讨论】:

    • 非常感谢@Uri Agassi
    猜你喜欢
    • 2014-09-15
    • 2012-12-25
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多