What to use for the `view_context` in a spec

A new instance of `ActionView::Base.new` will give you a collaborator that responds to most of the rails helper methods you would use in a view.

One limitation of using a new instance of `ActionView::Base`, is that it does not have access to the application routes. So any helper methods that use `url_for` under the hood will blow up the test.

However, I find that letting the view provide a block to handle this information is the better option anyway. It makes your presenter re-usable, and if you routes change then your presenter does not need to be updated - less churn.

comments powered by Disqus


joe@joejames.io. You wont find me on social networks (because I'm not there).