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: , , , , , , ,

5 Responses to “Testing helpers in Ruby on Rails 1.2”

  1. James H. Says:

    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.

  2. Alexander Lang Says:

    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 = request the the end of your setup method.

  3. James H. Says:

    Oops. Just a typo on my part now : ) Thanks for your help!

  4. Tom Says:

    Thank you so much for this tip! It saved me hours of work.

  5. Alexander Lang Says:

    you’re welcome :)

Leave a Reply