Topic: How to set request value in test case for Module method in Rails 2.0
Does anyone know how to set value for instance variables 'request', 'response'
in a library test case so it can be accessible in the called method?
I ran into a problem when I switched to Rails 2.0 with the deprecated instance variables
'request', p'arams', etc. in my mixin method.
My module is like this: (lib/foo/info.rb)
acceptHeader = request.env['HTTP_ACCEPT']
# blah blah
If I just include the module in my app everything works fine. I can get the header in
my app. However, I can't write test case
to test this module because it complains "request" is undefined local variable or method.
Here is my test case:
require File.dirname(__FILE__) + '/../test_helper'
# Re-raise errors caught by the controller.
class Info; def rescue_action(e) raise e end; end
class InfoTest < ActionController::TestCase
When the test is executed, and when it's in the printHeaders method, the request,response
are all nil. I tried using combination of request, @request but only @request is
avaiable in printHeaders method. However, @request is deprecated so I shouldn't be using
it in the library.
I also tried to put 'request' in the controller in test setup:
class << @controller
request = @request
request = @response
But I am getting this error when I step into the assignment:
#<RangeError: 0x25a61ba is recycled object>
It didn't help. The printHeaders method still doesn't get the request variable.
Does anyone know how to set the value for these built-in instance variables (request, response)
in the test setup for library test? The test is working fine in Rails 1.2 because I was
using @request all the time.