Rspec新手问题
我正在查看一些 rspec 示例代码并遇到了这个 -
lambda {
@my_object.function
}.should raise_error(ArgumentError, "Unknown tag type")
这是否意味着 rspec 猴子修补了 Proc
对象?否则我如何调用 should
方法?
I was looking at some rspec sample code and came across this -
lambda {
@my_object.function
}.should raise_error(ArgumentError, "Unknown tag type")
Does this mean that rspec monkey patches the Proc
object? Or otherwise how can I call the should
method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能不会称其为猴子修补,因为它扩展了核心 ruby Object 类。但是:是的,rspec 将在 Object 上定义 should 方法,因此任何东西都可以说它应该是“某事”
I probably wouldn't call it monkey patching since it extends the core ruby Object class. But: yes, rspec will define the should method on Object so anything can be say that it should "something"
它不太可能专门对
Proc
进行猴子补丁,因为所有内容都会响应should
。这种行为真的很重要吗?无论如何,一个简单的选择就是看一下源代码。 https://github.com/dchelimsky/rspec,特别是https://github.com/dchelimsky/rspec/blob/master/lib/spec/expectations/extensions/kernel.rb有关
内核
的更多信息 http://ruby-doc.org/core/classes/Kernel.htmlIt's unlikely it specifically monkey patches
Proc
since everything responds toshould
. Does this behavior really matter? Regardless, an easy choice is to just take a peek at the source. https://github.com/dchelimsky/rspec, specifically https://github.com/dchelimsky/rspec/blob/master/lib/spec/expectations/extensions/kernel.rbMore about
Kernel
http://ruby-doc.org/core/classes/Kernel.html