首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >期望422得到200个带rails的黄瓜

期望422得到200个带rails的黄瓜
EN

Stack Overflow用户
提问于 2018-08-06 02:25:37
回答 1查看 224关注 0票数 0

嗨,我正在做一个使用ruby-2.5.1和rails 5的ROR项目。我在我的rails应用程序中使用cucumber来测试api,我是新接触cucumber的。当我试图为无效数据定义特征时,我得到了预期的错误422,得到200。

我的功能文件:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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

请帮助我解决这个问题,我是第一次写这个黄瓜,所以我不知道如何测试无效的数据。请帮帮我。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-08-08 20:01:27

看起来你可能在你的应用程序中发现了一个bug。

如果在没有包含应用程序id的情况下,它的响应是422 "Unprocessable Entity“,而它的响应是200 (OK),那么看起来测试中的系统就有问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51697138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档