页面url大约为/people?search=name
current_path.should == people_path(:search => 'name')
但它没有说
expected: "/people?search=name"
got: "/people"
我们怎样才能让它通过?有什么办法吗?
页面url大约为/people?search=name
current_path.should == people_path(:search => 'name')
但它没有说
expected: "/people?search=name"
got: "/people"
我们怎样才能让它通过?有什么办法吗?
我更新了这个答案,以反映水豚的现代习俗.我认为这是理想的,因为这是公认的答案,也是许多人在寻找解决方案时提到的问题.尽管如此,判断当前路径的正确方法是使用Capybara提供的has_current_path?
matcher,如本文所述:Click Here
用法示例:
expect(page).to have_current_path(people_path(search: 'name'))
正如您在文档中看到的,还有其他选项可用.如果当前页面为/people?search=name
,但不管参数如何,您只关心它在/people
页面上,那么您可以发送only_path
选项:
expect(page).to have_current_path(people_path, only_path: true)
此外,如果要比较整个URL:
expect(page).to have_current_path(people_url, url: true)
汤姆·沃尔波尔指出了这种方法,这要归功于他.