Reputation: 11903
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?
Upvotes: 0
Views: 173
Reputation: 10547
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
Upvotes: 0
Reputation: 40277
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!)
Upvotes: 2