Sha256: 89b3e4cf525cd835873ddc2a663cd5f05ee3945fa2e980714a2d1b5a3e8363dc
Contents?: true
Size: 1.37 KB
Versions: 66
Compression:
Stored size: 1.37 KB
Contents
# RSpec matchers for API default JSON responses. # Creates a matcher like respond_forbidden or respond_not_found corresponding to each of the Api::V1.default_responses # Accepts optional overrides to the expected response body. # @example Override the description expected in the JSON body of a :forbidden response # expect(response).to respond_forbidden(description:"You can't create for that identity") ::CurationConcerns::API.default_responses.each_pair do |response_type, default_response_body| RSpec::Matchers.define "respond_#{response_type}".to_sym do |expectation_options| match do |response| @expected_response_body = expectation_options.nil? ? default_response_body : default_response_body.merge(expectation_options) expect(response.body).to_not be_empty json = JSON.parse(response.body) expect(response.code).to eq(@expected_response_body[:code].to_s) @expected_response_body.each_pair do |key, value| expect(json[key.to_s]).to eq(value.as_json) end end failure_message do |actual| "expected #{default_response_body[:code]} status code. Got #{actual.code} status code.\nexpected an Authentication Required response like this:\n #{@expected_response_body.to_json} \ngot\n #{actual.body}\nTo override expectations about the response body, provide a Hash of overrides in your call to :respond_#{response_type} " end end end
Version data entries
66 entries across 66 versions & 1 rubygems