What is the use of any_instance method in Rails
I see the following line in one of t开发者_运维问答he test files in rails. It has a method called as any_instance
. What is its use? Can someone please explain
http = Net::HTTP.new(Person.site.host, Person.site.port)
ActiveResource::Connection.any_instance.expects(:http).returns(http)
http.expects(:request).returns(ActiveResource::Response.new(""))
Thanks
any_instance
is a Mocha method. From the doc page:
Returns a mock object which will detect calls to any instance of this class.
Product.any_instance.stubs(:save).returns(false) product_1 = Product.new assert_equal false, product_1.save product_2 = Product.new assert_equal false, product_2.save
精彩评论