W moim projekcie Rails Używam RSpec-mocks użyciu any_instance ale chcę uniknąć tego komunikatu Deprecation:RSpec any_instance deprecation: jak to naprawić?
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.
Oto moje specyfikacje:
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
Oto mój kontroler:
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
Chciałbym użyć nowy: oczekiwać składni ale nie mogę znaleźć sposobu, aby właściwie go używać.
Używam RSpec 3.0.2.
jaka jest twoja wersja RSpec? –
@ArupRakshit 3.0.2 – Rowandish