Jump To …

The test directory

Return to the main rstat.us index

We like tests a lot. They give us confidence to change the code and know that we haven't broken anything known to have worked before. We use minitest/minispec-- we tend to use minispec's describe and it for organization and minitest's asserts. To run all the tests, you can run rake test. Run rake -T and look for test to see ways you can run subsets of tests.

The acceptance test directory contains tests that use the whole stack. They make use of capybara to simulate visiting pages, clicking links, and other browser-based behaviors. If you have found a bug while using rstat.us, it is often easiest to write an acceptance test first to reproduce it in exactly the way that you did as a user. These typically take a while to run.

acceptance/

The test data directory, right now, just contains VCR cassettes. No, not the precursors to DVDs-- it's a way to "record" and "replay" interactions with 3rd party resources such as hubs. This enables us to have consistently reproducible test cases, as well as not actually making updates all over the internet.

data/

This directory contains the tests for the decorator objects. These are Model View objects that make use of the draper gem and generate some of the HTML.

decorators/

Fabricators are ways to easily create objects in tests without having to specify every attribute every time. They are similar to Factories. Rstat.us uses fabrication for this.

fabricators/

The lib test directory has unit tests for the classes in lib that don't require any functionality from Rails. Want to see how awesome this is? Run rake test:lib and notice how much faster that runs compared to, say, rake test:models since lib doesn't need to load Rails.

lib/

The models test directory contains unit tests. We don't have unit tests for controllers or views-- most of the logic is (or should be) in the models. If you've isolated a problem to something you can reproduce with just objects, it would be best to create a unit test. They are faster to run and easier to be sure that no other component is involved with what's being tested.

models/

The test helper file has some configuration and methods that are useful for many of the tests.

test_helper.rb