Skip to content

Commit

Permalink
docs: add section on testing style that we promote (#1645) (#1649)
Browse files Browse the repository at this point in the history
* docs: add section on testing style that we promote (#1645)

* Update README.md

Co-authored-by: Matheus Sales <matheus_usales@hotmail.com>

---------

Co-authored-by: Matheus Sales <matheus_usales@hotmail.com>
  • Loading branch information
clemens and matsales28 authored Sep 6, 2024
1 parent ef9b917 commit e8f81e3
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit e8f81e3

Please sign in to comment.