Datasheet
Chapter 1: Building Resources
18
do is get a sense of the damage with the following (this output has been modified slightly for
readability):
$ rake
(in /Users/noel/Documents/Programming/ruby/soupsonline)
/usr/local/bin/ruby -Ilib:test
“/usr/local/lib/ruby/gems/1.8/gems/rake-
0.7.3/lib/rake/rake_test_loader.rb”
“test/unit/ingredient_test.rb”
“test/unit/recipe_test.rb”
Started
..
Finished in 0.327569 seconds.
2 tests, 2 assertions, 0 failures, 0 errors
/usr/local/bin/ruby -Ilib:test
“/usr/local/lib/ruby/gems/1.8/gems/rake-
0.7.3/lib/rake/rake_test_loader.rb”
“test/functional/ingredients_controller_test.rb”
“test/functional/recipes_controller_test.rb”
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-
0.7.3/lib/rake/rake_test_loader
Started
EEEEEEE.......
Finished in 1.732989 seconds.
14 tests, 13 assertions, 0 failures, 7 errors
Looking at the errors, it seems that all the functional tests of the ingredients controller failed, as expected.
The following section describes what you need to do to clean them up.
The Test Object
Rails sets up some test data in the fixtures directory, which can be loaded into your test directories to
enable database - backed objects to work. By default, each controller test loads the fixtures for the data
type the controller manages. However, now that the ingredients resource is subordinate to the recipe
resource, the ingredients controller test also needs to load the recipe fixtures. This enables the controller
to access recipe data during testing. Add the following line to
test/functional/ingredients_
controller_test.rb
, right below where the ingredient fixture is loaded:
fixtures :recipes
Now, in the tests, there are two things that need to be fixed consistently throughout the test. Each
individual test calls the
get , post , or put helper method to simulate the HTTP call. Each and every one
of those calls needs to add a parameter for the
recipe_id . You can do this by adding the argument to
each of the calls (remember to place a comma between hash arguments — for some reason I always
forget that comma):
:recipe_id = > 1
c01.indd 18c01.indd 18 1/30/08 4:02:26 PM1/30/08 4:02:26 PM