使用 RSpec 期望方法调用并代理到原始方法
我想发现 BDD 缺少 :include ActiveRecord::Base.find 方法的参数。所以我的想法是在规范中包含这样的内容:
ActiveRecord::Base.should_receive(:find).once.and_proxy_to_original_method
parent = SomeClass.find 34
parent.child.should be_loaded
parent.other_children.should be_loaded
如果 #child 或 #other_children 关联没有急切加载,则期望应该会失败,并显示以下内容: “预计 ActiveRecord::Base.find 会被调用一次,但它被调用了 2 次,参数如下:1. ...; 2. ...”
有谁知道是否有一些匹配器可以像这样工作或如何制作这。
谢谢
I want to discover with BDD missing :include params for ActiveRecord::Base.find method. So my idea is to have in spec something like this:
ActiveRecord::Base.should_receive(:find).once.and_proxy_to_original_method
parent = SomeClass.find 34
parent.child.should be_loaded
parent.other_children.should be_loaded
If #child or #other_children associations are not eager loaded, expectation should fail with something like:
"Expected ActiveRecord::Base.find to be invoked once but it was invoked 2 more times with following args: 1. ...; 2. ..."
Does anyone know if there's some matcher that works like this or how to make this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为我遇到了同样的问题此处。在你的具体情况下,我会这样做,我发现这很干净。
我相信您可以扩展 Rspec
Mocks::MessageExpectation
类以包含and_proxy_to_original_method
方法,应该不会太难,但我还没有看过。I think I had the same problem here. In your particular case I would do this which I find quite clean.
I believe you could extend the Rspec
Mocks::MessageExpectation
class to include theand_proxy_to_original_method
method, shouldn't be too hard, but I haven't looked.