eval_erb not recognizing instance variables in before
Reported by Andrew Zielinski | April 12th, 2008 @ 04:59 AM | in No-Milestone-Assigned
This used to work fine in version 1.1.3 but as soon as I got 1.1.4 from github my spec was failing.
My helper method
module ApplicationHelper
def li_for(record, *args, &block)
content_tag_for(:li, record, *args, &block)
end
end
And here is my spec
describe ApplicationHelper, "li_for" do
before(:each) do
@job = Job.new
@job.stub!(:id).and_return(1)
end
it "should render a list item" do
html = eval_erb <<-ERB
<% li_for(@job) do %>
<div>Content</div>
<% end %>
ERB
html.should have_tag('li#job_1')
html.should have_tag('li.job')
end
end
This is the error message that I get. It seems that the instance variables are no longer being passed into the 'erb context'. It works fine if I do this, as expected...
html = eval_erb <<-ERB
<% @job = Job.new %>
<% @job.stub!(:id).and_return(1) %>
<% li_for(@job) do %>
<div>Content</div>
<% end %>
ERB
This is the stack trace:
>RuntimeError in 'ApplicationHelper li_for should render a list item'
>Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
>/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/record_identifier.rb:66:in `dom_id'
>/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_view/helpers/record_identification_helper.rb:16:in `dom_id'
>/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_view/helpers/record_tag_helper.rb:54:in `content_tag_for'
>/Users/andrewzielinski/Projects/zaqt/app/helpers/application_helper.rb:5:in `li_for'
>(erb):1:in `eval_erb'
>./spec/helpers/application_helper_spec.rb:16:
>/usr/bin/rdebug:16:
Comments and changes to this ticket
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Behaviour Driven Development for Ruby.
