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.
Generators
- In this movie, we'll talk about Generators. That is generators degenerate placeholder files for your RSpec tests. The standard rails generators will create appropriate spec files for you. That is assuming that you have the RSpec Rails gem installed. If you have it installed, then Rails is going to assume that when you called rails generate model Customer that you're going to also want to create specs for your new class. So, as the same time, in the spec directory it will create a new directory called models, if it doesn't already exist, and then the appropriate Spec file, customer_spec.rb. If you need to generate the Spec file manually, perhaps because you're working on an existing application and the model file has already been generated, the process is almost the same. You just put rspec: in front of the type that you want it to create. Compare bullets two and four to see how similar they are. It's really just that addition of rspect: in front of model that's different. RSpec…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.