2011-12-08 11 views
1

はエラーとテストの要旨です:https://gist.github.com/1445801コンテキストブロックで "respond_with:success"を呼び出すときに "method_missing"エラーが発生するのはなぜですか?ここ

そして、ここではその要旨の内容は以下のとおりです。

require 'test_helper' 

class Api::HotelsControllerTest < ActionController::TestCase 

    context "When not logged in" do 
     should "forbid access when creating a hotel" do 
      hotel = Factory.build(:hotel) 
      post :create, :hotel => hotel 
      assert @response.code == "401" 
      assert Hotel.count.zero? 
     end 

     should "forbid access when listing available hotels" do 
      get :available 
      assert @response.code == "401" 
     end 

     should "forbid access when listing hotels" do 
      get :index 
      assert @response.code == "401" 
     end 

     should "forbid access when showing a hotel" do 
      hotel = Factory(:hotel) 
      get :show, :id => hotel.id 
      assert @response.code == "401" 
     end 

     should "forbid when updating a hotel" do 
      hotel = Factory(:hotel) 
      hotel.name = "Some new Hotel name" 
      put :update, :id => hotel.id, :hotel => hotel 
      assert @response.code == "401" 
     end 
    end 

    context "When logged in as basic user" do 
     setup do 
      @user = Factory(:user) 
      sign_in @user 
     end 

     context "on GET available hotel with no search criteria" do 
      setup do 
       get :available 
      end 

      should respond_with :success 
      should "be valid response" do 
       true 
      end 
     end 
    end 

end 

とテスト:成功、should respond_with(:success):周りの括弧を含む

** Invoke test (first_time) 
** Execute test 
** Invoke test:units (first_time) 
** Invoke test:prepare (first_time) 
** Invoke db:test:prepare (first_time) 
** Invoke db:abort_if_pending_migrations (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Execute db:abort_if_pending_migrations 
** Execute db:test:prepare 
** Invoke db:test:load (first_time) 
** Invoke db:test:purge (first_time) 
** Invoke environment 
** Execute db:test:purge 
** Execute db:test:load 
** Invoke db:schema:load (first_time) 
** Invoke environment 
** Execute db:schema:load 
NOTICE: CREATE TABLE will create implicit sequence "addresses_id_seq" for serial column "addresses.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "addresses_pkey" for table "addresses" 
NOTICE: CREATE TABLE will create implicit sequence "amenities_id_seq" for serial column "amenities.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "amenities_pkey" for table "amenities" 
NOTICE: CREATE TABLE will create implicit sequence "hotels_id_seq" for serial column "hotels.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "hotels_pkey" for table "hotels" 
NOTICE: CREATE TABLE will create implicit sequence "locations_id_seq" for serial column "locations.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "locations_pkey" for table "locations" 
NOTICE: CREATE TABLE will create implicit sequence "photos_id_seq" for serial column "photos.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "photos_pkey" for table "photos" 
NOTICE: CREATE TABLE will create implicit sequence "rooms_id_seq" for serial column "rooms.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "rooms_pkey" for table "rooms" 
NOTICE: CREATE TABLE will create implicit sequence "user_hotel_taggings_id_seq" for serial column "user_hotel_taggings.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "user_hotel_taggings_pkey" for table "user_hotel_taggings" 
NOTICE: CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "users_pkey" for table "users" 
** Execute test:prepare 
** Execute test:units 
** Invoke test:functionals (first_time) 
** Invoke test:prepare 
** Execute test:functionals 
/Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:429:in `method_missing': undefined method `respond_with' for Api::HotelsControllerTest:Class (NoMethodError) 
    from /Users/Eric/Work/webapp/test/functional/api/hotels_controller_test.rb:48:in `block (2 levels) in <class:HotelsControllerTest>' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in `call' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in `merge_block' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:301:in `initialize' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:310:in `new' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:310:in `context' 
    from /Users/Eric/Work/webapp/test/functional/api/hotels_controller_test.rb:43:in `block in <class:HotelsControllerTest>' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in `call' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in `merge_block' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:301:in `initialize' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:199:in `new' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:199:in `context' 
    from /Users/Eric/Work/webapp/test/functional/api/hotels_controller_test.rb:37:in `<class:HotelsControllerTest>' 
    from /Users/Eric/Work/webapp/test/functional/api/hotels_controller_test.rb:3:in `<top (required)>' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select' 
    from /Users/Eric/Work/webapp/.bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>' 
** Invoke test:integration (first_time) 
** Invoke test:prepare 
** Execute test:integration 
Errors running test:functionals! 
rake test TESTOPTS="-v" --trace 14.58s user 1.96s system 89% cpu 18.499 total 
+0

'shoulda-matchers' gemがインストールされていて、gemfileの' rspec' gemの後ろに来ていますか? – iwasrobbed

+0

私はrspecを使用していません。私のGemfile https://gist.github.com/1445981の内容は次のとおりです。 – erickreutz

+0

gemfileに 'rspec-rails'と' shoulda-matcher'の両方を含める必要はありませんか? ( 'shoulda-matcher'gem' README.rdoc' https://github.com/thoughtbot/shoulda-matchersから) – buruzaemon

答えて

0

てみてください。

0

私は同じ問題(Shoulda - 2.11.3と同じ名前のコントローラとあなたのような名前空間のコントローラ)を持っていて、Shouldaを3.1.1にアップグレードして修正しました。

関連する問題