2015-04-03 33 views
0

我想測試我的主頁。鏈接本身不應該。 爲什麼不是真的?Rails RSpec - 測試時有錯誤have_link

規格/特徵/ 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", "#") %> 
... 

=>

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)>' 

UPDATE: 誰都可以幫幫我?

+0

是什麼在你的routes.rb? – 2015-04-03 06:23:58

+0

@AndreyTurkin根'main_pages#home' – 2015-04-03 06:25:39

回答

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 
+0

不,它不起作用。我認爲問題不在通話頁面。鏈接「#」中的問題。 'expect(page).to have_link('About',href:about_path(locale:I18n.locale))''它工作。 – 2015-04-03 06:37:12