I'm reading up on rspec-mocks and got a little confused with Message Expectations.
A message expectation is an expectation that the test double will receive a message some time before the example ends. If the message is received, the expectation is satisfied. If not, the example fails.
validator = double("validator") validator.should_receive(:validate).with("02134") zipcode = Zipcode.new("02134", validator) zipcode.valid?
So my understanding is you create a dummy object and specify it should "receive" a message (which is this validate from ActiveModel) with argument 02134
. If it did at some point then this test will pass.
My question is:
Why can you pass
validator
toZipcode.new
? Is your application code supposed to expect to take in an extra argument (test double)?What does "receive a message" mean exactly for a test double? Does it mean it will be called by the message (in this case the
validate
method)?
Thanks!