Rails Testing Tips

Practical testing gotchas and patterns I ran into while testing Rails applications, from code coverage and flash messages to helper tests with RSpec.

Part 1

Rails Testing Tips: flash.now gotcha

How to test flash.now values that get cleared after rendering the view

Part 2

Rails Testing Tips: Code Coverage

Using rcov to track test coverage in a Ruby on Rails project

Part 3

Rails Testing Tips: Login gotcha

A workaround for testing controllers that require admin login from a different controller

Part 4

Rails Testing Tips: Stubbing controller methods in a helper test

In RSpec helper tests, the controller context is self -- use self.stub! to mock controller methods

Part 5

Rails Testing Tips: Testing a helper with a block

Two approaches to testing a Rails helper method that accepts a block using RSpec