RSPEC any_instance deprecation: how to fix it?

Sunday, July 6, 2014

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 syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead.


Here is my specs:



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


Here is my controller:



def create
@user = User.create(user_params)
if @user.save
render json: @user, status: :created, location: @user
else
render json: @user.errors, status: :unprocessable_entity
end
end


I'd like to use the new :expect syntax but I don't reach to find how to write it propely.







http://ift.tt/VuGTQM