I am using rspec-mock for test-driven-development.

I am starting implementing a single class and mocking/stubbing the other 
classes using rspec-mock. Mocking only objects of classes yet to be 
implemented works well. However when I try to mock a class method and 
instance methods for objects of the same class I am not sure how the 
preferred way to do this looks like.

I have code that e.g. looks like this:

new_book = Book.new
content = new_book.read_page(5)

I now want to mock out everything that has to do with the class "Book". In 
this example this would mean "Book.new" and "new_book.read_page"

Would I first mock the object using

book_object = double("Book")
allow(book_object).to receive(:read_page).and_return(...)

and then mock the class by 

book = class_double("Book")
allow(book).to receive(:new).and_return(book_object)


Is this the way to go?

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/0690a743-805e-410a-ba9d-2bc2a2ea930e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to