Sha256: 7ec737121fe0214e6c4c7c6bd6d9e574e63cffb39928fbd9808fc10b5d654fed

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

describe InfinumJsonApiSetup::RSpec::Matchers::HaveErrorPointer do
  include TestHelpers::Matchers::Response

  describe 'usage' do
    context 'when body includes error pointer' do
      it 'matches' do
        response = response_with_body(JSON.dump(errors: [{ source: { pointer: 'name' } }]))

        expect(response).to have_error_pointer('name')
      end
    end

    context "when body doesn't include specified error detail" do
      it 'fails and describes failure reason' do
        response = response_with_body(JSON.dump(errors: []))

        expect do
          expect(response).to have_error_pointer('name')
        end.to fail_with("Expected error pointers to include 'name', but didn't")
      end
    end

    context "when response isn't valid JSON" do
      it 'fails and describes failure reason' do
        response = response_with_body('')

        expect do
          expect(response).to have_error_pointer('name')
        end.to fail_with('Failed to parse response body')
      end
    end

    context "when response doesn't contain data attribute" do
      it 'fails and describes failure reason' do
        response = response_with_body('{}')

        expect do
          expect(response).to have_error_pointer('name')
        end.to fail_with('Failed to extract errors from response body')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infinum_json_api_setup-0.0.8 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb
infinum_json_api_setup-0.0.7 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb
infinum_json_api_setup-0.0.6 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb
infinum_json_api_setup-0.0.5 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb
infinum_json_api_setup-0.0.4 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb
infinum_json_api_setup-0.0.3 spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb