[rspec-users] render_template giving an odd error?

David Chelimsky dchelimsky at gmail.com
Tue Oct 12 02:17:03 EDT 2010

On Tue, Oct 5, 2010 at 8:03 AM, Matt Darby <matt at matt-darby.com> wrote:
> Hey all, I'm trying to migrate over to Rails3/RSpec2 and I cannot seem
> to get the specing of `render` right. I know there was some changes in
> RSpec2 that affect this, and I was hoping to get a bit of help.
> I have this is in a before block in a view spec:
> view.should render_template("attachments/index", :locals => {:obj =>
> @obj})

In rspec-2 you need to specify templates _after_ rendering:

it " .... " do
  view.should render_template("...")

> When I run the spec, it bombs out with this error:
> expecting <"attachments/index"> but rendering with <"">.
> Expected block to return true value.
> This doesn't tell me much, and aside from the RSpec2 syntax updates
> the spec hasn't changed (and used to work in Rails2).

In rspec-rails-1/rails-2, rspec monkey-patched the )(*&)(* out of
rails to be able to do things like mock partial calls, etc. This led
to a world of pain from release to release, so we're not doing that
anymore. The bad news is that you need to set up all the necessary
data to render any partials rendered by your views. The good news is
you can still specify which templates get rendered, as described

> This is a huge blocker for my app migration. I have 150+ models and
> use partials pretty often.
> Help is appreciated!


More information about the rspec-users mailing list