Testing block helpers13 Oct 08

Not as easy as you'd think. This bug 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:

 1  def eval_erb(text)
 2    ERB.new(text).result(binding)
 3  end
 4  
 5  describe SomeHelper do
 6   it "should work" do
 7   @result = eval_erb <<-ERB
 8   <% my_helper_name(MyThing.new(:body=>"foo") do %>
 9    this stuff is passed as the block text
10   <% end %>
11  ERB
12   @result.should == "exactly what I want"
13  end
14  end




Gwyn Morfey — facebookflickrtumblr — London UK