Soo*_*uNe 8 unit-testing rspec ruby-on-rails
我希望我的所有单元测试都使用www.test.host而不是默认值test.host.
我尝试过ENV['HTTP_HOST']进入config/environments/test.rb,但是没有得到它.
我的目的是避免在我的控制器测试中重定向,在我的测试中检查response对象的输出是:
#<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" ...>>
Run Code Online (Sandbox Code Playgroud)
如果它有所作为,我正在使用Rails3和RSPEC2
gtd*_*gtd 13
你可以通过设置request.host测试来实现.您可以通过将此添加到您的全局test_helper.rb(无论如何,在Rails 3.1中,不确定以前的版本,但我认为它类似)来全局完成:
class ActionController::TestCase
setup do
request.host = "www.test.host"
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3455 次 |
| 最近记录: |