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.

Implicitly defined subjects

Implicitly defined subjects - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Implicitly defined subjects

- In the last movie we saw how to define the subject of our examples. And we did this explicitly using RSpecs subject method. So in RSpec file we had subject and then a block of code after it, Car.new. Whenever we wanted to refer to the subject we just simply called subject in our example and it referred to that helper method, which then called the code in the same way that let did. Well RSpec also allows us to have implicitly defined subjects. See the line at the top that says describe and then has a string for Car after it? If you'll recall when we first talked about describe I told you that it would accept either a string or a classname. And a string works fine, there's no reason not to. However using a classname gives you an extra benefit on top of that, and that is the benefit of having an implicitly defined subject. Let me show you. Believe it or not, this code works exactly like the code on the previous slide. I don't have to specify the subject. RSpec does it for me. As soon…

Contents