I would like all my unit tests to use www.test.host
instead of the default test.host
.
I tried setting ENV['HTTP_HOST']
in config/environments/test.rb
, but that didn't get it.
My purpose is to avoid a redirect in my controller test, the output of inspecting the response
object in my test is:
#<ActionController::TestResponse:0x000001059ed378, ..., @header={"Location"=>"http://www.test.host", ... , @status=301, @body=["<html><body>You are being <a href=\"http://www.test.host\">redirected</a>.</body></html>"], ... , "REQUEST_METHOD"=>"GET", "SERVER_NAME"=>"example.org", "SERVER_PORT"=>"80",... , "HTTP_HOST"=>"test.host", "REMOTE_ADDR"=>"0.0.0.0" ...>>
If it makes a difference, I'm using Rails3 and RSPEC2
You do it by setting request.host
in your test. You can do it globally by adding this to your test_helper.rb
(in Rails 3.1 anyway, not sure about previous versions, but I think it's similar):
class ActionController::TestCase
setup do
request.host = "www.test.host"
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With