RSpec any_instance deprecation: how to fix it?

后端 未结 2 837
醉话见心
醉话见心 2021-02-03 17:32

In my Rails project I\'m using rspec-mocks using any_instance but I want to avoid this deprecation message:

Using any_instance from rspec-mocks\' old :should synta

2条回答
  •  再見小時候
    2021-02-03 18:11

    Use allow_any_instance_of:

    describe (".create") do
      it 'returns error when...' do
        allow_any_instance_of(User).to receive(:save).and_return(false)
        post :create, user: {name: "foo", surname: "bar"}, format: :json
        expect(response.status).to eq(422)
      end
    end
    

提交回复
热议问题