为什么我收到以下错误? 在控制台中运行rspec测试时,我收到错误消息' post'不明。然而,失败的代码行是这样构造的:
def getCellValue(Cell cell){
def result
switch (cell.getCellType()) {
case Cell.CELL_TYPE_FORMULA:
// if(cell.getCellType() == Cell.CELL_TYPE_ERROR){
// result = 0
// } else {
// result = cell.getNumericCellValue()
// }
////////////////////////////////////////////////
result = cell.getNumericCellValue()//i need a condition for this case
break
case Cell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue()
break
case Cell.CELL_TYPE_STRING:
result = cell.getStringCellValue()
break
case Cell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue()
break
case Cell.CELL_TYPE_BLANK:
result = null
break
default:
result = cell.toString()
break
}
return result
}
因此:
post :create, valid_params
这是错误
it "assigns the new post to @post" do
post :create, post: {title: RandomData.random_sentence, body: RandomData.random_paragraph}
expect(assigns(:post)).to eq Post.last
end
答案 0 :(得分:1)
如果您正在使用Rails 5,那么您需要将post
对象包含在params
关键字参数中,请尝试:
post :create, params: { post: { title: RandomData.random_sentence, body: RandomData.random_paragraph } }