Testing helpers in Ruby on Rails 1.2
We are just migrating one of our projects from Rails 1.1.6 to 1.2.2. One of the problems we encountered was, that Recipe 44: Write tests for your helpers from Rails Recipes (by the way Advanced Rails Recipes will come out in Augut 2007) is not working anymore. The line
@controller.send :initialize_current_url
resulted in a
After some messing around, we found out that the following setup method solves this:
Happy testing
Tags: helpers, programming, rails, rails-1.2, test, testing, tests, unit-tests





March 12th, 2007 at 7:07 pm
Hey there. I stumbled upon this when trying to get recipe 44 to work in Rails 1.2 as well.
Did you ever get the above to work? Running your code (after fixing a spelling error) results in Rails complaining that @request is nil.
March 13th, 2007 at 3:29 pm
hi james,
thanks for the hint, just fixed the spelling error. where does your @request-error come from? we are not using @request anywhere…
if you are accessing @request from within your tests, try to add
@request = requestthe the end of your setup method.March 13th, 2007 at 10:57 pm
Oops. Just a typo on my part now : ) Thanks for your help!
September 30th, 2007 at 12:57 am
Thank you so much for this tip! It saved me hours of work.
September 30th, 2007 at 1:52 pm
you’re welcome