尽管存在链接,RSpec 应该 has_link 失败 [英] RSpec should have_link fails despite link existence
本文介绍了尽管存在链接,RSpec 应该 has_link 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 RSpec 测试一直失败.
I have a RSpec test that keeps failing.
subject { page }
visit user_path(user)
it { should have_link('Settings', href: edit_user_path(user)) }
但是当我自己加载页面时,我可以看到链接运行良好.有任何想法吗 ?也没有拼写错误.
But when I load the page myself I can see that the link is working well. Any ideas ? No spelling mistake as well.
可以看到 RSpec 在测试中加载的页面吗?
Possible to see the page that RSpec loaded in the test?
推荐答案
您的访问 user_path(user)
未在正确的上下文中执行.
Your visit user_path(user)
isn't executing in the right context.
尝试:
subject { page }
it do
visit user_path(user)
should have_link('Settings', href: edit_user_path(user))
end
或者:
subject { page }
before { visit user_path(user) }
it { should have_link('Settings', href: edit_user_path(user)) }
如果您想查看 html,可以使用 save_and_open_page
语句.
If you would like to see the html, you can use a save_and_open_page
statement.
这篇关于尽管存在链接,RSpec 应该 has_link 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文