From the course: Ruby: Testing with RSpec

Unlock the full course today

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

Collections

Collections - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Collections

- In this movie, we'll take a look at RSpec's Collection Matchers. Now, what do I mean by a collection? Really what we're talking about are arrays, hashes or strings. Strings are collection of letters. They work in a lot of ways very similar to an array, right? We have different order of letters, just like we have different order of elements inside an array. Those are the three things we're going to be looking at with Collection Matchers. Let's start with arrays. Let's say I have a simple array, [1,2,3]. I can use the include matcher to assert that a value should be included in that array so I can expect the array to include 3 or I can provide more than one value. The order doesn't matter here. What I'm actually making are two different expectations. I'm expecting the array to include 2, and I'm expecting the array to include 3. I'm writing two arguments, both of them need to be true. I can use the start_with or end_with matchers to make an assertion about the values that the array…

Contents