In the book Growing Rails Applications in Practice, the authors present a standard way of writing controllers.
This project illustrates my approach on how to test these controllers, based on the following principles:
- The specs should fully isolated from the database
- No use of any fixtures or factories
- Use verifying doubles
- Generates no warnings from RuboCop default configuration
- Each scenario is clearly split into its Setup, Execution and Verification phases.
- No use of
before
blocks. Minimal use oflet
- Prefer spies over mocks where appropriate.
- Extract duplication into plain Ruby methods
- Uses
expect
instead ofallow
for more confident specs. - Ruby 1.9 hash syntax
- No use of
tap
I made some minor changes from the code in the book:
- Use
all
instead ofscoped
for Rails 4 compatibility - Use
||
instead ofor
to avoid RuboCop warning - Use single line
if
modifier to avoid RuboCop warning - Add a condition to
build_note
to prevent unnecessary setting