Skip to content

Commit

Permalink
Documentation: added a section about testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Senko committed Nov 23, 2024
1 parent 68c2aff commit b4159f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This release marks the gem to be stable enough.
- `undefined method 'configure' for module RSpec`.
- Instance variables assignment in views.

### Documentation

- Added a section about testing.


## [0.4.0] — 2024-10-29

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,29 @@ View context is set automagically to enable helpers:
> [!NOTE]
> The built-in `helper` generator is overridden with `presenter` one to generate presenters instead of helpers.
## Testing presenters

Magic Presenter supports RSpec and Test::Unit.
The appropriate tests are generated alongside a presenter.

Testing presenters is much like [testing Rails helpers](
https://guides.rubyonrails.org/testing.html#testing-helpers
).
Since the test class inherits from `ActionView::TestCase`, Rails’ helper methods such as `link_to`, `localize` and many others are available in tests.

As any presenter is a decorator, see also [how to test decorators](
https://github.com/Alexander-Senko/magic-decorator#testing-decorators
).

### RSpec

Presenter specs are expected to live in `spec/presenters`.
If a different path is used, `type: :presenter` metadata should be set explicitly.

### Test::Unit

Tests related to the presenters are located under the `test/presenters` directory and inherit from `Magic::Presenter::TestCase`.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down

0 comments on commit b4159f7

Please sign in to comment.