开发者

Rspec newbie question

开发者 https://www.devze.com 2023-04-07 12:41 出处:网络
I was looking at some rspec sample code and came across this - lambda { @my_object.function }.should raise_error(ArgumentError, \"Unknown tag type\")

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号