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

Version Path
curation_concerns-1.7.8 spec/support/matchers/api_responses.rb
curation_concerns-1.7.7 spec/support/matchers/api_responses.rb
curation_concerns-2.0.0 spec/support/matchers/api_responses.rb
curation_concerns-2.0.0.rc2 spec/support/matchers/api_responses.rb
curation_concerns-1.7.6 spec/support/matchers/api_responses.rb
curation_concerns-1.7.5 spec/support/matchers/api_responses.rb
curation_concerns-1.7.4 spec/support/matchers/api_responses.rb
curation_concerns-1.7.3 spec/support/matchers/api_responses.rb
curation_concerns-1.7.2 spec/support/matchers/api_responses.rb
curation_concerns-2.0.0.rc1 spec/support/matchers/api_responses.rb
curation_concerns-1.7.1 spec/support/matchers/api_responses.rb
curation_concerns-1.7.0 spec/support/matchers/api_responses.rb
curation_concerns-1.7.0.beta1 spec/support/matchers/api_responses.rb
curation_concerns-1.6.3 spec/support/matchers/api_responses.rb
curation_concerns-1.6.2 spec/support/matchers/api_responses.rb
curation_concerns-1.6.1 spec/support/matchers/api_responses.rb
curation_concerns-1.6.0 spec/support/matchers/api_responses.rb
curation_concerns-1.5.0 spec/support/matchers/api_responses.rb
curation_concerns-1.4.0 spec/support/matchers/api_responses.rb
curation_concerns-1.3.3 spec/support/matchers/api_responses.rb