Tests

Test Driven Development
Growstuff uses Test Driven Development, which means that we write tests before writing code.


 * 1) Decide what feature you're implementing
 * 2) Describe the feature in tests
 * 3) Run the tests -- they will fail, because you haven't written the code yet
 * 4) Write the code to implement the feature
 * 5) Run the tests again -- your tests should now pass!
 * 6) Commit!

For further reading, see Learning resources.

Running tests
To run all the tests for Growstuff, change into your growstuff directory and run:

rake

To run some subset of tests, you can run eg.

rspec app/views/home/

(or whatever directory contains the ones you want to run.)

Making tests run faster
The tests can be really slow to run. To deal with this, we tried out a gem called spork, which is a test server to save Rails from loading stuff it doesn't need. The result should have been faster tests, but unfortunately we actually ended up with faster tests and annoyingly-frequent moments of confusion and frustration when crucial code changes weren't loaded properly. So we removed it. Experiments with other systems meant to speed up tests (like parallel_tests) haven't yielded enough benefits to be worth rolling out.

So, yeah, it's a known problem. Can you help?

For now the best thing is probably to run only a relevant subset of tests in your normal edit/test/loop cycle (using rspec spec_file1 spec_file2...), and only run the full test suite before a commit.

Automatically running tests before commit
Wouldn't it be great if you didn't accidentally commit with broken tests? We've set up a hook so that every time you run git commit the tests will run automatically. To get this feature in your dev environment:

rake hooks

Note that if you run git commit -m "blah" rather than git commit and then using the editor to write your message, then the tests will actually run after your commit and won't prevent the commit from happening.