Ich habe einen sehr einfachen Controller, der so aussieht.Rails Rspec-Controller-Test gibt einen unbekannten Hash
module Veterinarians
module Dictionaries
class SpecialitiesController < ApplicationController
respond_to :json
skip_before_action :check_current_vet, only: %i(index)
def index
@specialities = Veterinarians::Speciality.all
respond_with(@specialities)
end
end
end
end
Ich habe einen RSPC-Controller-Test, der so aussieht.
require 'rails_helper'
Rails.describe Veterinarians::Dictionaries::SpecialitiesController, type: :controller do
# Not returning a response body in JSON when testing RSPEC (https://github.com/rails/jbuilder/issues/32)
render_views true
routes { Veterinarians::Engine.routes }
let(:user) { double :user, id: 123 }
before { sign_in(user) }
context '#index' do
let(:speciality) { double :speciality, id: :some_id, value: :some_val }
before { allow(Veterinarians::Speciality).to receive(:all).and_return [speciality] }
subject { get :index, format: :json }
it { is_expected.to have_http_status(:ok) }
it { expect(JSON.parse(subject.body)).to include('id' => 'some_id', 'value' => 'some_val') }
end
end
Das zweite Beispiel schlägt mit diesem Fehler fehl.
expected [{"__expired" => false, "name" => "speciality"}] to include {"id" => "some_id", "value" => "some_val"}
Irgendwelche Hinweise, warum dies nicht und wo die Hash würde mit „__expired“ herkommt?
Ich habe andere Tests, die diese gleiche Testmethode verwenden, die erfolgreich sind.