【发布时间】:2017-10-27 15:08:19
【问题描述】:
我在 rspec 中有以下测试用例
let(:detail) { FactoryGirl.create(:detail) }
let(:url) do
"/detail/#{detail.detail_id}"\
"/user/#{detail.user.id}/details"
end
let(:location_header) do
detail_url(detail_id: detail.detail_id,
user: detail.user.id, location: detail.location)
end
before do
post url, params: params
end
context 'when valid location and value are passed, detail is created successfully.' do
let(:params) {{detail_app_id: detail.detail_app_id, location: detail.location, value: 'value'}}
it { expect(response.status).to eq(201) }
end
我正在学习 ruby rspec,但出现错误“{\"error\":\"Validation failed: location has already been taken\"}"
当我在参数中更改位置值时,它会通过,但由于我正在为它创建工厂女孩,我想使用该值而不是传递不同的值。 知道为什么我会收到这个错误吗?
【问题讨论】:
-
请编辑您的答案以显示整个工厂文件。
标签: ruby ruby-on-rails-4 rspec