嗨,我正在做一个使用ruby-2.5.1和rails 5的ROR项目。我在我的rails应用程序中使用cucumber来测试api,我是新接触cucumber的。当我试图为无效数据定义特征时,我得到了预期的错误422,得到200。
我的功能文件:
Feature: Registration Endpoint
Scenario: User registration
Given an application with application_id "1"
When the client make a valid POST /registartions request with application_id: "1"
Then response should have status 200
Scenario: using blank application id
When the client make a POST /registartions request with blank application-id
Then response should have status 422 and JSON:
"""
{ "error": "application_id does not exists" }
"""我的steps文件:
Given("an application with application_id {string}") do |string|
string
end
When("the client make a valid POST \/registartions request with application_id: {string}") do |string|
params = {
"data":{
"type":"users",
"attributes":{
"email": "s2@gmail.com",
"password":"password",
"password-confirmation":"password"
}
}
}
header 'application-id', "#{string}"
post '/api/registrations', params
end
Then("response should have status {int}") do |int|
expect(last_response.status).to be(int)
end
When("the client make a POST \/registartions request with blank application-id") do
params = {
"data":{
"type":"users",
"attributes":{
"email": "s2@gmail.com",
"password":"password",
"password-confirmation":"password"
}
}
}
header 'application-id', ''
post '/api/registrations', params
end
Then("response should have status {int} and JSON:") do |int, string|
expect(last_response.status).to be(int)
end请帮助我解决这个问题,我是第一次写这个黄瓜,所以我不知道如何测试无效的数据。请帮帮我。提前谢谢。
发布于 2018-08-08 20:01:27
看起来你可能在你的应用程序中发现了一个bug。
如果在没有包含应用程序id的情况下,它的响应是422 "Unprocessable Entity“,而它的响应是200 (OK),那么看起来测试中的系统就有问题。
https://stackoverflow.com/questions/51697138
复制相似问题