Rails port/Testing

From OpenStreetMap Wiki
Jump to: navigation, search

Rails has a full testing framework built in. Hopefully we can have enough tests that when run, will know whether the code has changed in a way that will cause a problem. Most of the test data for tests is loaded from test/fixtures automatically. Some of the test data is embedded in the tests.

Within your rails_port directory, run

 rake test

This will copy the database schema of the development database and use it for the test db, and also run all the tests.

If you want to run only one test file run the command (this example is for the amf controller):

 ruby test/functional/amf_controller_test.rb

When you are trying to debug a specific test within a file append -n and the function name (for example):

 ruby test/functional/amf_controller_test.rb -n test_whichway_toobig

These tests are automatically running every commit with the results shown at http://cruise.shaunmcdonald.me.uk/

To have the tests auto run whenever you save take a look at the ZenTest gem/autotest. It is clever in that it will only run the tests that have code that has had changes in it http://nubyonrails.com/articles/autotest-rails


To get an idea of the coverage of the code install the rcov gem:

 sudo gem install rcov

and then run the command:

 rcov --rails -x /Gems/ test/*/*.rb

Gotchas

Personal tools
Namespaces
Variants
Actions
site
Toolbox