If you have any questions, please don't hesitate to ask me :). So we need to use allow to assume that this object has some methods and returns predefined values. This object isn't existed in your real system, it doesn't own methods and attributes. To answer this question, we should refer to the concept of Test Doubles:Ī test double is an object that stands in for another object in your system during a code example Sum up:Ī big difference between them is that ASSUME and EXPECT Deep magic: You EXPECT that when book object calls title method, it'll return that string "The RSpec Book". The error is not getting raised when I am trying to run the test case. allowanyinstanceof (ClientClass).to receive (:instancemethod).andraise (ErrorClass, 'Error raised') def tobetestedcode do some stuff client ClientClass.new client.instancemethod do other stuff end. allow: book = double("book")Īllow(book).to receive(:title) rspec raiseerror not working with allowanyinstance. You know allow and expect are used in rspec-mocks, but you are confused with them ?.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |