【发布时间】:2015-08-06 10:06:25
【问题描述】:
这是一段代码,它会在第 5 行引发错误“args 数量错误(1 对 0):
describe 'PATCH #update' do
context 'title is empty' do
it 'should not update page' do
page = create(:page)
patch :update, { id: page.id, page: FactoryGirl.attributes_for(:page, title: nil) }, format: :json
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
Rails 控制器:
def update
if @page.update(page_params)
render json: @page
else
status :unprocessable_entity
end
end
其他测试工作得很好,但这对于#update's else - 没有。
无法理解,这是什么问题,我该如何解决? (功能正常,但测试失败)
【问题讨论】:
-
你有什么问题?
-
如何解决这个错误,这很明显。
-
status :unprocessable_entity不应该是render json: @page.errors, status: :unprocessable_entity吗? -
@Pavan,你说得对。谢谢,将其发布为答案,它有效。
标签: ruby-on-rails ruby rspec