Rails Recipe 44 -- Write Tests for Your Helpers [Corrected]

I'm having trouble getting this to work.

The recipe is simple:

def setup
  @controller = SomeController.new
  request = ActionController::TestRequest.new
  @controller.instance_eval { @params = {}, @request = request }
  @controller.send(:initialize_current_url)
end

But with Rails 1.2.3 I'm getting this error:

1) Error:
  test_x(ApplicationHelperTest):

TypeError: can't clone NilClass
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1082:in `clone'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1082:in `initialize_current_url'
    application_helper_test.rb:20:in `send'
    application_helper_test.rb:20:in `setup_without_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/
lib/active_record/fixtures.rb:576:in `setup'

Any ideas?

Thanks

I think that's changed to since the original Recipes book was
published, and it's now:

@controller.instance_variable_set(:@url,
(ActionController::UrlRewriter.new @request, {}))

A setup that works for me is:

def setup
   super

   @request = ActionController::TestRequest.new
   @controller = StubController.new
   @controller.request = @request

   @controller.instance_variable_set(:@url,
(ActionController::UrlRewriter.new @request, {}))

ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
end

Cheers,

Mike