0

雖然按照教程5.3.4佈局鏈接測試失敗。
RailsTutorial.org學習導軌5.3.4佈局鏈接測試

這是測試跑:

$ rails generate integration_test site_layout

這是收到的錯誤:

/usr/local/rvm/gems/ruby-2.2.1/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"

/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run rake db:migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.

開始

FAIL["test_layout_links", SiteLayoutTest, 2015-05-10 20:31:00 +0000] 
test_layout_links#SiteLayoutTest (1431289860.34s) 
    Expected exactly 2 elements matching "a[href="/"]", found 0.. 
    Expected: 2 
     Actual: 0 
    test/integration/site_layout_test.rb:8:in `block in <class:SiteLayoutTest> 

1/1: [====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00 

Finished in 0.53147s 
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips 

這是文件(測試/集成/site_layout_test.rb)更改d運行測試並收到錯誤:

require 'test_helper' 

class SiteLayoutTest < ActionDispatch::IntegrationTest 

    test "layout links" do 
    get root_path 
    assert_template 'static_pages/home' 
    assert_select "a[href=?]", root_path, count: 2 
    assert_select "a[href=?]", help_path 
    assert_select "a[href=?]", about_path 
    assert_select "a[href=?]", contact_path 
    # test "the truth" do 
    # assert true 
    end 
end 

我在做什麼錯?

下面是應用程序/視圖/佈局/ _header.html.erb文件中的代碼:

<header class="navbar navbar-fixed-top navbar-inverse"> 
    <div class="container"> 
    <%= link_to "sample app", root_path, id: "logo" %> 
    <nav> 
     <ul class="nav navbar-nav navbar-right"> 
     <li><%= link_to "Home", root_path %></li> 
     <li><%= link_to "Help", help_path %></li> 
     <li><%= link_to "Log in", '#' %></li> 
     </ul> 
    </nav> 
    </div> 
</header> 
+1

測試代碼看起來不錯。錯誤消息的第二部分是關於測試結果(來自「FAIL」)。它預計有2個到root_path的鏈接,它確實發現了0. (test/integration/site_layout_test.rb:8表示:在該文件的第nr 8行,這是關於root_path的。) 所以問題不在你的測試文件中,但在其他地方。 看看你的app/views/layouts/_header.html.erb文件。那裏有兩條根路線,它們是你測試中的count = 2。 – Mauddev

+0

謝謝@Mauddev。我從一開始就一直遇到問題,他們沒有工作。文件app/views/layouts/_header.html.erb的代碼如下。 –

+0

<%= link_to "sample app", root_path, id: "logo" %>

回答

0

我的問題是,當我在_header部分,而不是#寫root_path,我沒有刪除''。刪除那些一切正常工作後。不要忘記_footer部分。

+0

請檢查此[URL](http://stackoverflow.com/help)它將有助於提高您的內容質量 –

+0

謝謝@willie –