如何模拟 OpenCascade?
OpenCascade 是来自 Hashery 的递归 OpenStruct:
http://rubyworks.github.com/hashery/
它允许您可以通过键序列引用哈希中的嵌套值:
h = {:a=>1,:b=>{:x=>1,:y=>2}}
c = OpenCascade.new(h)
c.b.y
=> 2
我们使用它来读取 YAML 配置。现在我们想模拟测试中的值,但是
mock(c.b).y { 5 }
不起作用。我们如何嘲笑它?
OpenCascade is a recursive OpenStruct from Hashery:
http://rubyworks.github.com/hashery/
It allows you to refer to nested values in a hash via a sequence of keys:
h = {:a=>1,:b=>{:x=>1,:y=>2}}
c = OpenCascade.new(h)
c.b.y
=> 2
We're using it to read in a YAML config. Now we'd like to mock the values in tests, however
mock(c.b).y { 5 }
doesn't work. How do we mock it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当问题被问及
OpenCascade
的method_missing
创建了一个新的每次查询Hash
时都会生成一个对象:这意味着在该版本中存在以下情况:
这就是模拟
cb
不起作用的原因...此后已修复。
When the question was asked the implementation of
OpenCascade
'smethod_missing
created a new object each time aHash
was queried:This means that in that version the following:
That's why mocking
c.b
didn't work...It has since been fixed.