Почему я получаю ошибку «method_missing» при вызове «before_with: success» в контексте блока? - PullRequest
1 голос
/ 08 декабря 2011

Вот суть ошибки и теста: https://gist.github.com/1445801

А вот суть содержания:

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

И тест:

** 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

Ответы [ 2 ]

0 голосов
/ 06 февраля 2013

У меня была та же самая проблема (с той же версией Должа - 2.11.3 - и с контроллером пространства имен, как у вас), и я исправил ее, обновив Должу до 3.1.1.

0 голосов
/ 21 декабря 2011

Попробуйте включить квадратные скобки: успех, should respond_with(:success).

...