Category Archives: Testing

Rails comes with built-in testing. We discuss all things testing-related–everything from setup of tests and the testing framework to best-practices on how to test different aspects of your application (and how best to structure your tests).

Drilling Down into Validation Failure

Rails provides model-level validation, which is easy and DRY. But if you have a class that validates multiple fields, how can you verify if validation is failing on the right fields? ActiveRecord provides a convenient errors method with an invalid? method you can call; it takes a field name. Continue reading

Posted in Testing | Tagged , , | 1 Comment

Foxy Fixtures Explained

Rails integrated a plugin called Foxy Fixtures into the core API. How does it work? It allows you to refer to other fixtures by name, instead of by ID (so no more hard-coded IDs). But there’s a gotcha–the IDs are generated automatically, so they’re not 1 or 2 like you might expect (for your first and second fixtures). Continue reading

Posted in Gems and Plugins, Testing | Tagged , , | 1 Comment

Testing Rails Applications

In addition to providing you with a testing framework, Rails generates tests when you use scaffolding. You can even write your own tests (beyond these basic ones)–unit, functional, and integration tests. Here, we discuss how to set up the test environment (it requires its own test database), and run the tests. Continue reading

Posted in Testing | Tagged | Comments Off