Skip to content

Commit

Permalink
docs: add section on testing style that we promote (thoughtbot#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens committed Aug 26, 2024
1 parent 8890f3d commit b41f6b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ RSpec.describe Person, type: :model do
end
```

### A Note on Testing Style

If you inspect the source code, you'll notice quickly that `shoulda-matchers`
is largely implemented using reflections and other introspection methods that
Rails provides. On first sight, this might seem to go against the common
practice of testing behavior rather than implementation. However, as the
available matchers indicate, we recommend that you treat `shoulda-matchers` as
a tool to help you ensure correct configuration and adherence to best practices
and idiomatic Rails in your models and controllers - especially for aspects
that in your experience are often insufficiently tested, such as ActiveRecord
validations or controller callbacks (a.k.a. the "framework-y" parts).

For your specific business logic, on the hand, you should very much favor
testing behavior/outcome over testing implementation: Not only will this
facilitate refactoring, but the reality is that no generic testing tool will
ever map adequately to your specific domain. (But you could certainly write
your own custom matchers and use `shoulda-matchers` as an inspiration.)

## Matchers

Here is the full list of matchers that ship with this gem. If you need details
Expand Down

0 comments on commit b41f6b9

Please sign in to comment.