简体   繁体   English

Minitest:调用#assert_current_path 时水豚错误?

[英]Minitest: Capybara error when calling #assert_current_path?

I want to compare the expected path and current path to justify whether the test is passed within Minitest.我想比较预期路径和当前路径以证明测试是否在 Minitest 中通过。

I found the method Capybara::SessionMatchers#assert_current_path.我找到了 Capybara::SessionMatchers#assert_current_path 方法。 I guess this method can fulfill my requirement.我想这种方法可以满足我的要求。

But when I wrote:但是当我写道:

page.assert_current_path()

In my test, the error showed: no #assert_current_path method在我的测试中,错误显示: no #assert_current_path method

I've seen the Capybara::Session has included the Capybara::SessionMatchers .我已经看到Capybara::Session包含Capybara::SessionMatchers I'm confused of why I cannot call the #assert_current_path method.我很困惑为什么我不能调用#assert_current_path方法。 Does Capybara have the functionality to compare current path and expected path? Capybara 是否具有比较当前路径和预期路径的功能? coz use page content to justify the result is not stable for me.因为使用页面内容来证明结果对我来说不稳定。

确保您正在运行 Capybara 2.5+ - 直到 2.5.0 才添加assert_current_path 匹配器

page.assert_current_path('/expected/path')

Try this尝试这个

uri = URI.parse(current_url)

if you need check additional params如果您需要检查其他参数

"#{uri.path}?#{uri.query}".should == your_path(:your_params => 'your_value')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM