ruby-on-railsrspecrspec-railsactive-model-serializersactivemodel

Rspec test that uses active model serializer in nested engine not passing


... serialized_animals = ActiveModel::Serializer::CollectionSerializer.new(animals, each_serializer: ApiHandler::Api::Private::MobileApp::V8::AnimalSerializer)
          aggregate_failures 'response details' do
            expect(JSON.parse(response.body)['data']['animals']).to(eq(JSON.parse(serialized_animals.to_json)))
          end ...

The AnimalSerializer sits in animal_engine/app/serializers/api_handler/api/private/mobile_app/v8

Weirdly serializing a single item works.

I get the following error

UncaughtThrowError: uncaught throw :no_serializer


Solution

  • Use :serializer instead of :each_serializer. Not sure why it was failing but that fixes it.