如何使用Capybara查询string获取当前path
这个页面的URL类似于/people?search=name而我使用的是水豚的current_path方法,它只返回/people 。 
 current_path.should == people_path(:search => 'name') 
但它没有说
 expected: "/people?search=name" got: "/people" 
我们如何能通过? 有没有办法做到这一点?
 我已经更新了这个答案,以反映在水豚的现代公约。 我认为这是理想的,因为这是可以接受的答案,在寻找解决scheme时会提到许多人。 这就是说,检查当前path的正确方法是使用has_current_path? 由水豚提供的匹配,如在这里logging: 点击这里 
用法示例:
 expect(page).to have_current_path(people_path(search: 'name')) 
 正如您在文档中看到的,其他选项可用。 如果当前页面是/people?search=name但是只关心它在/people页面上,而不考虑param,则可以发送only_path选项: 
 expect(page).to have_current_path(people_path, only_path: true) 
另外,如果你想比较整个url:
 expect(page).to have_current_path(people_url, url: true) 
感谢Tom Walpole指出这种方法。
我用_urlreplace_path方法来实现比较完整的url和参数。
 current_url.should == people_url(:search => 'name') 
只是现代更新这个问题。 使用Capybara 2.5+时检查current_paths的最佳做法是使用current_path匹配器,它将使用Capybaras等待行为来检查path。 如果想检查request_uri(path和查询string)
 expect(page).to have_current_path(people_path(:search => 'name')) 
如果只想要path部分(忽略查询string)
 expect(page).to have_current_path(people_path, only_path: true) 
如果想匹配完整的url
 expect(page).to have_current_path(people_url, url: true) 
匹配器将采取与==或正则expression式相匹配的string
 expect(page).to have_current_path(/search=name/) 
我知道一个答案已经被选中,但我只是想提供一个替代解决scheme。 所以:
 要得到path和查询string,就像Rails中的request.fullpath一样,你可以这样做: 
 URI.parse(current_url).request_uri.should == people_path(:search => 'name') 
 你也可以在你的testing类(像ActionDispatch::IntegrationTest )这样做(这是我做的): 
 def current_fullpath URI.parse(current_url).request_uri end 
希望这可以帮助。
编辑:正如Tinynumberes提到的,这不符合端口号的URL。 保持在这里,以防其他人有同样的好主意。
 current_url[current_host.size..-1] 
 与URI.parse(current_url).request_uri完全一样(35个字符),但由于不涉及显式的URIparsing,所以速度可能更快。 
我已经提出了一个请求,将其添加到Capybara: https : //github.com/jnicklas/capybara/pull/1405