Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add section on testing style that we promote (#1645) #1649

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,25 @@ 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 testing your application's unique business logic, however, we recommend focusing on
behavior and outcomes over implementation details. This approach will better support
refactoring and ensure that your tests remain resilient to changes in how your code
is structured. While no generalized testing tool can fully capture the nuances of your
specific domain, you can draw inspiration from shoulda-matchers to write custom
matchers that align more closely with your application's needs.

## Matchers

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