嗨,我正在使用ruby-2.5.1和rails 5进行ROR项目。我在rails应用程序中使用黄瓜来测试api,我是黄瓜新手。当我尝试为无效数据定义功能时,我得到了预期的错误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" }
"""
我的步骤文件:
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
请帮助我解决这个问题,因为我是第一次写黄瓜,所以我不知道如何使用无效数据进行测试。请帮我。预先感谢。
答案 0 :(得分:0)
您似乎在应用程序中发现了一个错误。
如果当您不包括应用程序ID时,它打算以422“不可处理的实体”响应进行响应,并且以200(确定)进行响应,则似乎被测系统有问题。