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.

Shared examples

Shared examples - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Shared examples

- In this movie, we'll learn about Shared Examples. Be warned, we're starting to leave the shallow end of the swimming pool now. Shared examples can be very complex. If you feel like you don't understand it fully on the first viewing, that's okay. Just make sure you understand what purpose they serve, so that you'll be able to come back to them later when you need them. Let's imagine that we have specs for a Product class. I have three examples shown. I've written out the first one, but I've left the second two as still pending. These examples test whether a product can be sorted by its position attribute. I've found that assigning a sort order is one of the most common development tasks that we do. We do it over and over and over again. If other classes need to be sorted by a position attribute too, then it would not be efficient for us to cut and paste these examples into another spec file or example group. That would violate the principle of don't repeat yourself in a big way…

Contents