I see the following line in one of the 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With