From the course: Ruby: Testing with RSpec

Unlock the full course today

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

Complex expectations

Complex expectations - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Complex expectations

- Now we get to start having some fun with the matchers that we know, by mixing and matching them. We're going to look at two things, Compound Expectations and Composing Matchers. Compound Expectations are pretty simple. It's just the ability to use And and Or in our expectations. And requires that both expressions be true. Or requires that either one of the expressions be true. And and Or also have aliases with the Ampersand or the single Pipe. Let me give you an example. Let's say that I have a string, Lynda, and I assign that to the variable S. I should expect S to Start With capital L dot And, and then End With lowercase A. See how that works. Both of those things should be true. It should start with L and end with A. Now you could actually handle this by writing two separate expectations. I expect S to start with L. I expect S to end with A. This just allows us to do it all in one. But Or, actually offers you something that you couldn't get by writing separate expectations. We…

Contents