From the course: Ruby: Testing with RSpec

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Message argument constraints

Message argument constraints - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Message argument constraints

- Now that we know about message expectations we can look at message argument constraints. Most of the time when we're passing messages to objects we don't care that much about what the arguments are that we're passing with that message. Those are arguments that are going to be passed on to the method that it calls. Nine times out of ten we're probably the ones passing in those arguments ourselves so we know what they are but sometimes that's not the case, and sometimes we wanna check up on those arguments and make sure that they are the values that we think they are and that's where argument constraints come in. The way that we do that is by having our message expectation, and here I have expect(dbl).to receive (:sort) but then after that we chain on another method call for with. So, now we're expecting the dbl to receive sort and we're expecting the dbl to receive it with the argument that I've provided. In this case, the string name. So, now in the last line, I call dlb.sort and…

Contents