assert_template against the same partial with different locals #3675

Closed
luisobo opened this Issue Nov 18, 2011 · 6 comments

Projects

None yet

6 participants

@luisobo
luisobo commented Nov 18, 2011

I have a view like this

<%= render :partial => 'widget', :locals => { :param => "10" } %>
<%= render :partial => 'widget', :locals => { :param => "20" } %>

Then in RSpec I'm doing this:

rendered.should render_template :partial => 'widget', :locals => { :param => "10" }
rendered.should render_template :partial => 'widget', :locals => { :param => "20" }

The first expectation is failing. It says something like expected "10", found "20". It looks like it's only saving the last partial and checking all my expectations against the last one.

The second expectation is passing.

The RSpec matcher render_template uses assert_template so the problem is the same there.

@frodsan
Contributor
frodsan commented Apr 29, 2012

@luisobo is this still an issue?

@kytrinyx
Contributor

@luisobo Can you provide a test application or reproduce the issue with test-unit?

@steveklabnik
Member

The rspec definition is here.

The rails definition is here.

I'm not familiar enough with how this is supposed to work. :/ I'm trying to make a rails app that demonstrates this now.

@steveklabnik
Member

I cannot for the life of me figure out how to make an integration test with test-unit.

Anyway, it would seem to me that the issue is here: https://github.com/rails/rails/blob/3cba6eee66a4c25b93839ea6fd1da08d7780f2de/actionpack/lib/action_controller/test_case.rb#L106

This is going to write two values for the same key, which is why you're seeing the second only.

You could fix this by only writing one assertion per test. ;)

@senny
Member
senny commented Oct 8, 2012

@steveklabnik is this considered a bug? I could try to write up a patch. I added a failing test case to illustrate the problem.

@steveklabnik
Member

I think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment