我正在使用工厂女孩来创建我的对象。我想知道为什么我必须执行以下操作:
RSpec.describe V1::SlotsController, type: :controller do
let(:valid_slot) { create(:slot) }
let(:valid_attributes) { attributes_for(:slot) }
describe "DELETE destroy" do
it "destroys the requested slot" do
slot = Slot.create! valid_attributes # not working without this line
expect {
delete :destroy, { id: slot.id }
}.to change(Slot, :count).by(-1)
end
end
end
如果我不覆盖插槽,而只使用 factory_girl 创建的插槽,则测试不会通过。为什么?