Skip to content
Browse files

Merge pull request #513 from carols10cents/route_stubbing_documentation

Document how to stub route helper functions in isolated tests. Addresses...
  • Loading branch information...
2 parents 94f66e4 + 943f25b commit e20604ac02023c37609011174adedddf493fe6eb @steveklabnik steveklabnik committed Apr 5, 2013
Showing with 23 additions and 0 deletions.
  1. +23 −0 README.md
View
23 README.md
@@ -390,6 +390,29 @@ Draper::ViewContext.test_strategy :fast do
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 require Rails.
+
+If you are using RSpec, minitest-rails, or the Test::Unit syntax of minitest,
+you already have access to the Draper `helpers` in your tests since they
+inherit from `Draper::TestCase`. If you are using minitest's spec syntax
+without minitest-rails, you can explicitly include the Draper `helpers`:
+
+```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 RSpec's `stub` method):
+
+```ruby
+helpers.stub(users_path: '/users')
+```
+
## Advanced usage
### Shared Decorator Methods

0 comments on commit e20604a

Please sign in to comment.
Something went wrong with that request. Please try again.