在嵌套引擎中使用活动模型序列化程序的 Rspec 测试未通过

问题描述

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

AnimalSerializer 位于animal_engine/app/serializers/api_handler/api/private/mobile_app/v8

奇怪地将单个项目序列化。

我收到以下错误

UncaughtThrowError: uncaught throw :no_serializer

解决方法

使用:serializer 而不是:each_serializer。不知道为什么它失败了,但修复了它。