0
我有一个RSpec测试,看起来像这样:rspec的尴尬语法检测更换计数
describe 'on DELETE to :destroy' do
before do
expect { delete :destroy, id: 6 }.to change(ModelName, :count)
end
it { is_expected.to respond_with :success }
it { is_expected.to render_template :destroy }
end
我觉得别扭其上更改测试算before
块里面,我并不需要运行它两次。我希望能找到一个语法是这样的,而不是:
describe 'on DELETE to :destroy' do
before do
delete :destroy, id: 6
end
it { is_expected.to respond_with :success }
it { is_expected.to render_template :destroy }
it { is_expected.to change(ModelName, :count) }
end
但是第三次试验给了我以下错误:由于错误信息提示,你需要传递一个块
expected #count to have changed, but was not given a block
我得到一个类似的错误消息'它{is_expected.to变化{ModelName.count}}' - '预期的结果已经改变了,但没有给出block' –