页面url类似于/people?search=name
当我用current_path
它还回水原的方法/people
只有。
current_path.should == people_path(:search => 'name')
但它不能说
expected: "/people?search=name"
got: "/people"
我们怎么才能让它过去?有办法吗?
示例用法:
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)
我换了_路径法_URL来实现对完整URL与参数的比较。
current_url.should == people_url(:search => 'name')