开发者

Changing the hostname for tests in Rails

Apparently, while running tests in Rails, the hostname is "www.example.com". If I run root_url in a test it'll return "http://www.example.com/".

Since I'm doing an app that requires another hostnames, is there a way to change the default hostname to something else, so I don't have to specify it every time I generate a URL开发者_StackOverflow社区 in the tests?

Thanks.


Path/url helpers take hostname from request object. So in test you can do something like this:

request.host = "another-domain.com"


It seems the answer is no, in the test code, you have to specify the host when calling url helpers.


Yes, I think in you can do something like this in your config/environments/test.rb file:

config.action_controller.asset_host = "127.0.0.1"

ps this is untested for now. I know i did something like this but once but the code is on my computer at work. I will check it tomorrow if it doesn't work.


Well, it depends how do you test. For example, if you're using Capybara for your test suite you can specify default_host

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜