In The RSpec Book, in Chapter 3, the RSpec test for the Mastermind Game, contains two examples. One ensures that “Welcome to Mastermind!” is printed on the screen, the other one ensures that “Enter guess:” is printed on the screen.
However the order in which these messages are printed on the screen is not asserted in the examples, while it’s important.
How can we ensure that the messages are printed in a specific order while keeping the examples focused and concise?
Thanks in advance.
That was in chapter 3 in a very early beta. Did you not get messages from the prags to update PDF?
I hadn’t got it from prags. However last night I bought the updated version and looks like a lot has changed.
I had a look at the latest version of the book, which uses let to setup variables, etc. but it still does not ensure that the “Enter guess:” is printed after “Welcome to Mastermind”. Or I am wrong?
Hey B - I took a peek back at it myself and it looks like you are correct. If you want to ensure order, just add .ordered at the end of the two expectations (see http://relishapp.com/rspec/rspec-mocks/v/2-6/dir/message-expectations).
Mail (will not be published) (required)