[rspec-users] view_context in specs

Patrick J. Collins patrick at collinatorstudios.com
Wed Nov 2 23:29:13 EDT 2011

> > Is the best way to get a real-world view context in there to do something like:
> > 
> > Blah.new(ActionView::Base.new) ?
> > 
> > Or does RSpec have something magical already setup for this sort of thing?
> Nope. rspec-rails doesn't know that you want to write presenters :)
> I'd say just go w/ the real deal.

Ok cool, thanks.  It turns out ActionView::Base.new is a bit of a pain to try to
use in this case since it lacks configuration of view paths and such.  So what
appears to be the simplest way to get this functionality is to do:

@context = ActionController::Base.new.view_context

then you can do @context.render, @context.content_tag, etc.

Patrick J. Collins

More information about the rspec-users mailing list