0
我想測試,如果外部URL活躍在這裏:Rails的外部URL測試
class LinkSuccessTest < ActionDispatch::IntegrationTest
...
def test_external_url_success
@urls.each do |url|
get url
assert_response :success
end
end
end
,但是當有一個路徑參數它不工作。例如,
$ rails console
> app.get "http://www.toms.com/"
=> 200
> app.get "http://www.toms.com/coffee"
=> 404
在這裏,我怎樣才能得到正確的響應狀態?
在上述上下文中,'get'向您的應用發送請求,而不是外部網站。 '> app.get「http://www.toms.com/」'從你的應用中獲取'/'。 'app.get「http://www.toms.com/coffee」'試圖從您的應用中獲取'/ coffee'。不是'http:// www.toms.com /'。 –
您應該使用'機械化'寶石與外部網站進行交互。有關示例,請參閱http://mechanize.rubyforge.org/EXAMPLES_rdoc.html。 –
非常感謝@Prakash Murthy – kangkyu