parameter
使用 Ruby on Rails 中的 RSwag 和 RSpec,是否可以通过?发送未定义为 a 的参数run_test!
?
示例测试:
# frozen_string_literal: true
require "swagger_helper"
describe "Resources", type: :request, swagger_doc: "api/resources.json" do
path "/resources" do
get "get resources" do
tags "resources"
parameter name: "sort[column]",
in: :query,
type: :string,
enum: ["created_at", "updated_at"]
required: false
parameter name: "sort[order]",
in: :query,
type: :string,
enum: ["asc", "desc"]
required: false
response "422", "Unprocessable Entity" do
context "with unrecognized param" do
# define sort[direction] here
run_test! do |respone|
expect(json_response["errors"]).to contain_exactly(
# my serialized response error
)
end
end
end
end
end
end
我想把sort[direction]
我的context
. 到目前为止我已经尝试过:
let(:"sort[direction]") { "asc" }
let(:sort) { { direction: "asc" } }
let(:sort) { { "direction" => "asc" } }
无济于事 - 我得到了 HTTP 200 成功,即使通过 Postman 发送的具有sort[direction]
定义的相同请求以预期的 HTTP 422 Unprocessable Entity 响应。