<?xml version="1.0" encoding="UTF-8"?>
<article>
  <body>Not as easy as you'd think. &lt;a href='http://rspec.lighthouseapp.com/projects/5645/tickets/376-eval_erb-not-recognizing-instance-variables-in-before'&gt;This bug&lt;/a&gt; is relevant. It seems that not only can you not create your instance variables outside the ERB and pass them in, you can't even reliably create them inside the ERB. I ended up doing this: 
 
[ruby]
def eval_erb(text)
  ERB.new(text).result(binding)
end

describe SomeHelper do
 it "should work" do
 @result = eval_erb &lt;&lt;-ERB
 &lt;% my_helper_name(MyThing.new(:body=&gt;"foo") do %&gt;
  this stuff is passed as the block text
 &lt;% end %&gt;
ERB
 @result.should == "exactly what I want"
end
end
[/ruby]</body>
  <category-id type="integer">1</category-id>
  <created-at type="datetime">2008-10-13T08:24:02-04:00</created-at>
  <file nil="true"></file>
  <id type="integer">157</id>
  <picture nil="true"></picture>
  <title>Testing block helpers</title>
  <updated-at type="datetime">2008-10-13T08:24:26-04:00</updated-at>
</article>
