2011-02-01 23 views
2

Rails 3のテストでいくつか問題があります。現在、Rails2アプリをRails3にアップグレードしています。私はテストのためにshouldaを使用しています。汎関数:私の機能テストでは、私はGETが成功すくいテストと機能テストを実行しながら、私は次のエラーを取得しています最後の行の次にRails 3でテストする必要があります:respond_with:success

context "GET to :blame" do 
    should "mark a song as blamed" do 
    get :blame, :id => @song.id 
    assert_equal Blame.count, 1 
    get :blame, :id => @song.id 
    assert_equal Blame.count, 2 
    end 
    should respond_with :success 
end 

で応答しなければならないこと、shouldaでテストしています:

1) Error: 
test: a visitor GET to :blame should respond with 200. (SongsControllerTest): 
NoMethodError: undefined method `response_code' for nil:NilClass 
    /Users/23tux/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:57:in `response_code' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:48:in `correct_status_code?' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:30:in `matches?' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/assertions.rb:53:in `assert_accepts' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/context.rb:324:in `block in should' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/context.rb:382:in `call' 
    /Users/23tux/.rvm/gems/[email protected]/gems/shoulda-2.11.3/lib/shoulda/context.rb:382:in `block in create_test_from_should_hash' 

私はRuby 1.9.2、Rails 3.0.3、Shoulda 2.11.3を使用しています。 希望、誰かが私を助けることができます。

THX、 タキシード

答えて

2

2は、ブロックが個別に実行されなければならないと何の要求が故にrespond_withエラーのために作られないであろう。次のような設定ブロックでリクエストを行う必要があります。

context "GET to :blame" do 
    setup do 
    get :blame, :id => @song.id 
    end 
    should "mark a song as blamed" do 
    assert_equal Blame.count, 1 
    end 
    should respond_with :success 
end 
関連する問題