2011-12-03 21 views
0

Simply Rails 2という本のチュートリアルの実行中にアプリを構築していますが、いくつかのテストに合格するのに問題があります。Rails Appで失敗したテスト

は、ここで私が受けてるエラーです:

1) Failure: 
test_should_show_index(StoriesControllerTest) 
[/Users/ryanclark/Projects/shovell/test/functional/stories_controller_test.rb:8:in `test_should_show_index' 
/Users/ryanclark/.rvm/gems/ruby-1.8.6-p420/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in `run']: 
<nil> expected to not be nil. 

    2) Failure: 
test_should_show_navigation_menu(StoriesControllerTest) 
[/Users/ryanclark/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.0.2/lib/action_controller/assertions/selector_assertions.rb:297:in `assert_select' 
/Users/ryanclark/Projects/shovell/test/functional/stories_controller_test.rb:44:in `test_should_show_navigation_menu' 
/Users/ryanclark/.rvm/gems/ruby-1.8.6-p420/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in `run']: 
Expected at least 2 elements matching "#navigation li", found 3. 
<false> is not true. 

    3) Failure: 
test_should_show_new_form(StoriesControllerTest) 
[/Users/ryanclark/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.0.2/lib/action_controller/assertions/selector_assertions.rb:297:in `assert_select' 
/Users/ryanclark/Projects/shovell/test/functional/stories_controller_test.rb:18:in `test_should_show_new_form' 
/Users/ryanclark/.rvm/gems/ruby-1.8.6-p420/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in `run']: 
Expected at least 3 elements matching "form p", found 4. 
<false> is not true. 

マイプロジェクトがGithub上にあり、誰かが見て、私を助けてしまう場合、私は本当に少しの洞察力をいただければ幸いです。

また、私は詳細とコードを提供してくれるだけで、投稿を簡潔にしています。

+0

ちょっと、ライアン、あなたの問題を解決しましたか?私の答えは有益でしたか? –

+0

こんにちはアレックス、私はあなたの答えを読んで、すべてが理にかなっています。本のコードがオフであるか、これらのものがそこにあるかどうかはわかりません。私はまだコードを通過する時間がなかったが、間違いなく私が知るものをあなたに知らせるだろう。私のコードと本の両方をチェックしたい。助けてくれてありがとう! –

答えて

1

失敗1:テスト中 'test_should_show_index' at 8行assert_not_nil assigns(:stories)

テストデータベースに 'votes_count> = 5'の店舗はありません。ここではストーリー(stories.yml)のためのあなたの固定具は、次のとおりです。

one: 
    name: My shiny weblog 
    link: http://poocs.net 
    user: patrick 

two: 
    name: SitePoint Forums 
    link: http://www.sitepoint.com/forums/ 
    user: patrick 

すべての物語は(それが0である、デシベル/ schema.rb、ライン20を参照)votes_countのデフォルト値を持っています。あなたは、このようにこのような何かにフィクスチャを変更、votes_count> = 5を持っている少なくとも一つの物語を必要とする:

one: 
    name: My shiny weblog 
    link: http://poocs.net 
    user: patrick 

two: 
    name: SitePoint Forums 
    link: http://www.sitepoint.com/forums/ 
    user: patrick 
    votes_count: 5 

失敗2:試験でライン44 assert_select '#navigation li', 2

で 'test_should_show_navigation_menuを' あなたのナビゲーションdiv要素を持っています3つの<li>タグの代わりに、2予想(application.html.erbを参照してください):

<ul id="navigation"> 
    <li><%= link_to 'Front page stories', stories_path %></li> 
    <li><%= link_to 'Upcoming stories', bin_stories_path %></li> 
    <li><%= link_to 'Submit a new story!', new_story_path %></li> 
</ul> 

失敗3:テスト中 'test_should_show_new_form' 18行目assert_select 'form p', :count => 3

あなたのフォームには、3つではなく<p>個のタグが含まれています。新しいアクション方法(new.html.erb)のテンプレート内で見つけることができます:

<% form_for(@story) do |f| %> 
    <p> 
    <b>Name</b><br /> 
    <%= f.text_field :name %> 
    </p> 

    <p> 
    <b>Link</b><br /> 
    <%= f.text_field :link %> 
    </p> 

    <p> 
     description:<br /> 
     <%= f.text_area :description %> 
    </p> 

    <p> 
    <%= f.submit "Create" %> 
    </p> 
<% end %> 

希望することができます。

関連する問題