2010-01-11 57 views
4

我的一些控制器操作在其邏輯中使用了request.host參數。在集成測試中,我可以使用host!方法來設置主機。如何在功能測試中實現同樣的功能?指定Rails功能測試的主機

回答

7

找到自己的解決方案:

def setup 
    @request.host = 'test.example.com' 
end 

的@request對象請求之間重複使用,所以它僅需要設置一次。

+1

有關操作請求變量的更多信息,請參閱http://stackoverflow.com/questions/2029488/change-value-of-request-remoteip-in-ruby-on-rails/其中唯一的區別是remote_ip被修改而不是主機 – Veger 2010-01-11 12:00:26