Iteration B2: Unit Testing of Models
One of the joys of the Rails framework is that it has support for testing baked right in from the start of every project. As you’ve seen, from the moment you create a new application using the rails command, Rails starts generating a test infrastructure for you. Let’s take a peek inside the models subdirectory to see what’s already there:
| depot> ls test/models |
| product_test.rb |
product_test.rb is the file that Rails created to hold the unit tests for the model we created earlier with the generate script. This is a good start, but Rails can help us only so much. Let’s see what kind of test goodies Rails generated inside test/models/product_test.rb when we generated that model:
Get Agile Web Development with Rails 5.1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.