2015-04-05 46 views
0

我在Ruby on Rails上有點新,目前正在關注Michael Hartl的Rails教程。關於收益率耙測試的錯誤與提供

正如我所用 '衛士' 的測試,它說,

After running bundle exec rake test below are the results: 
 

 
1) Failure: 
 
StaticPagesControllerTest#test_should_get_home [c:/Usrs/Code Box/workspace/feed/test/static_pages_controller_test.rb:7]: 
 
<Home | Ruby on Rails Sample App> expected but was <Feed>.. 
 
Expected 0 to be >= 1. 
 
    
 
    3 runs, 6 assertions, 1 failures, 0 errors, 0 sips.

我想每一頁上的標題更改動態所以這裏是我的應用程序視圖,

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <title><%= yield(:title) %> | Ruby on Rails Sample App</title> 
 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
 
    <%= csrf_meta_tags %> 
 
</head> 
 
    <body> 
 
    <%= yield %> 
 
    </body> 
 
</html>

,這裏是作爲錯誤消息指出主視圖,

<% provide(:title, "Home") %> 
 
<h1>Lipsum</h1> 
 
<p> 
 
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime, distinctio! Quidem eaque labore eos ipsam a aliquam, eius. Distinctio quo reprehenderit nostrum commodi quod assumenda consequatur officia, placeat sit fugit. 
 
</p>

最後,這裏的測試控制器,

class StaticPagesControllerTest < ActionController::TestCase 
 
    test "should get home" do 
 
    get :home 
 
    assert_response :success 
 
    assert_select "title", "Home | Ruby on Rails Sample App" 
 
    end

+0

測試中的哪一行導致錯誤?最好包含完整的錯誤跟蹤。 – 2015-04-05 02:50:03

+0

第7行 - 這是 - assert_select「標題」,「主頁| Ruby on Rails示例應用程序」 – 2015-04-05 16:30:35

回答

0

你的代碼您的觀點是「Ruby on Rails教程示例」應用程序「,但您的測試期待」Ruby on Rails示例應用程序「。這是一個錯字還是問題?

+0

噢,是的,對不起,錯字。儘管如此,標題並沒有顯示它只是說應用程序名稱。 – 2015-04-05 16:28:52

0

「啊哈!」時刻。看來我正在編輯錯誤的Application.html.erb文件從另一個文件夾中導致錯誤,因爲原始Application.html.erb上的聲明沒有標題上的「收益」。

已解決。謝謝!