jos*_*hsz 14 ruby bdd ruby-on-rails cucumber
Given I have a rails app
And I'm using cucumber
And I'm using capybara
And I have an action that results in a redirect_to "http://some.other.domain.com/some_path"
When I test this action
Then the in-app portion of the test works fine
But I see this error: No route matches "/some_path" with {:method=>:get} (ActionController::RoutingError)
Run Code Online (Sandbox Code Playgroud)
所以capybara被正确地重定向到" http://some.other.domain.com/some_path "但由于某种原因它认为它应该处理我的应用程序内的url的路径部分.注意使用" http://some.other.domain.com/ "时,水豚没有任何问题- 如果我重定向到没有路径部分的网址,我的测试就会通过.
这是一个错误吗?
我想我遇到了和你一样的问题:我只想确认一下,我的代码会使用正确的状态代码重定向到给定的URL,但我不想对该URL做任何事情.
问题是,该站点按预期返回重定向,但Rack :: Test将所有内容解释为正在测试的应用程序,并且该URL可能不存在.但是我们可以捕获错误并查看响应的样子.除了capybara的默认驱动程序,这可能不适用于其他任何东西.
begin
click_button('Pay with Paypal')
rescue ActionController::RoutingError
end
expect(page.status_code).to eq(302)
expect(page.response_headers['Location']).to include('paypal.com/cgi-bin/websrc')
Run Code Online (Sandbox Code Playgroud)
您使用哪个驱动程序?Rack-Test 驱动程序不允许您从其他域请求内容。如果 Capybara 使用 Selenium 或 Culerity 执行此操作,那么这绝对是一个错误。如果您想帮助修复它,那么编写一个失败的规范将非常感激:)
归档时间: |
|
查看次数: |
4237 次 |
最近记录: |