Rspec newbie question
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 ca开发者_运维百科n I call the should
method?
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"
1.should eq(2)
class MySuperObject
end
MySuperObject.new.should_not respond_to(:monkey!)
It's unlikely it specifically monkey patches Proc
since everything responds to should
. 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.rb
More about Kernel
http://ruby-doc.org/core/classes/Kernel.html
精彩评论