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.

Solution: Restaurant

Solution: Restaurant - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Solution: Restaurant

- Hopefully you had good luck solving the restaurant challenge. Now, let me show you my solution. So in my restraurant_spec file, the first thing I did was the attributes. Notice here that I'm using the implicitly defined subject because I'm describing Restaurant, and I'm using the actual class name, not a string, then I can call subject right here and have an implicitly defined subject. So remember, that's the same thing as calling Restaurant.new with no options at all, just Restaurant.new. So, here I'm using Restaurant.new, and I'm trying to set name = "Test" and then read it back to see if I can both read and write to it. I'm doing the same thing for the cuisine and for the price. That's all there is to setting up those attributes. Just very quickly, trying to write to them, trying to read back from them, and see if I was able to succeed. So then load_file was already done for you, so we're not gonna look at that. And then the next one is the class method for all. It returns an…

Contents