我想测试我的主页。不应该链接到自己。 为什么不是真的?
规格/特征/ main_pages_spec.rb
require 'spec_helper'
RSpec.describe "main pages", :type => :features do
subject { page }
...
context "root page" do
it "should have the link 'Home'" do
visit root_path
expect(page).to have_link('Home', href: '#')
end
end
...
end
应用程序/视图/ main_pages / home.html.erb
...
<%=link_to("Home", "#") %>
...
=&GT;
main pages root page should have the link 'Home'
Failure/Error: expect(page).to have_link('Home', href: '#')
expected #has_link?("Home", {:href=>"#"}) to return true, got false
# ./spec/features/main_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
更新: 有人可以帮忙吗?
答案 0 :(得分:0)
试试这个:
context "root page" do
before { visit root_path }
it "should have the link 'Home'" do
expect(page).to have_link('Home', href: '#')
end
end