【发布时间】:2014-08-27 00:39:03
【问题描述】:
在我的 Rails 项目中,我使用 rspec-mocks 并使用 any_instance,但我想避免此弃用消息:
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.
这是我的规格:
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
这是我的控制器:
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
我想使用 新的 :expect 语法,但我不知道如何正确使用它。
我正在使用 RSpec 3.0.2。
【问题讨论】:
-
你的 Rspec 版本是多少?
标签: ruby-on-rails ruby testing rspec