Document how to stub route helper functions in isolated tests. Addresses #506.
This commit is contained in:
parent
18e27a511e
commit
dbe8a81ca7
21
README.md
21
README.md
|
@ -390,6 +390,27 @@ Draper::ViewContext.test_strategy :fast do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Stubbing route helper functions
|
||||||
|
|
||||||
|
If you are writing isolated tests for Draper methods that call route helper
|
||||||
|
methods, you can stub them instead of needing to include Rails.
|
||||||
|
|
||||||
|
To get access to the Draper `helpers` in your test, include them in your tests:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
describe YourDecorator do
|
||||||
|
include Draper::ViewHelpers
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can stub the specific route helper functions you need using your
|
||||||
|
preferred stubbing technique (this example uses mocha):
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
helpers.stubs(users_path: '/users')
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Advanced usage
|
## Advanced usage
|
||||||
|
|
||||||
### Shared Decorator Methods
|
### Shared Decorator Methods
|
||||||
|
|
Loading…
Reference in New Issue