预计422获得200黄瓜铁路
嗨我正在研究一个带有ruby-2.5.1和rails 5的ROR项目。我在我的rails应用程序中使用黄瓜来测试api我是黄瓜的新手。 当我试图定义无效数据的function时,我得到错误预期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
请帮助我解决这个问题我第一次写这个黄瓜,所以我不知道如何测试无效数据。 请帮我。 提前致谢。
看起来您可能在应用程序中发现了一个错误。
如果它意味着当您不包含应用程序ID时响应422“不可处理的实体”响应,并且它以200(OK)响应,那么看起来似乎被测系统存在问题。
- 在Rails中的一个ActiveRecord事务中更新多个记录
- Ruby和Amazon S3如何打开文件并进行身份validation?
- 在Rails模型/表中validationpresense vs null false
- Rails:如何连接到旧的PostgreSQL(你的PostgreSQL版本(70417)太旧了,请升级!)
- 在所有文件中添加“#coding:utf-8”
- 长期安装rails-4.0.2的ri文档
- Rails 4.2.0.beta2 – 无法连接到LocalHost?
- 如何使用Rails ActiveRecord进行LEFT OUTER JOIN?
- 使用Sinatra和jQuery而无需在POST上重定向