Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_template against the same partial with different locals #3675

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

assert_template against the same partial with different locals #3675

luisobo opened this issue Nov 18, 2011 · 6 comments

Comments

@luisobo
Copy link

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
Copy link
Contributor

frodsan commented Apr 29, 2012

@luisobo is this still an issue?

@kytrinyx
Copy link
Contributor

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

@steveklabnik
Copy link
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
Copy link
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:

actual_locals = @locals[expected_partial.to_s.sub(/^_/,'')]

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
Copy link
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
Copy link
Member

I think so.

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

No branches or pull requests

6 participants