Sha256: 6ab28f6eecf6a0aa79e0ff9e8d6a5ae570ffa6006c87c412315d79edc973edf7

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

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

  describe 'usage' do
    context 'when body includes related resource' do
      it 'matches' do
        response = response_with_body(JSON.dump(included: [{ type: 'user', id: '1' }]))

        expect(response).to include_related_resource('user', 1)
      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(included: []))

        expect do
          expect(response).to include_related_resource('user', 1)
        end.to fail_with("Expected included items to include (type = user, id = 1), 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 include_related_resource('user', 1)
        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 include_related_resource('user', 1)
        end.to fail_with('Failed to extract included 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/include_related_resource_spec.rb
infinum_json_api_setup-0.0.7 spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb
infinum_json_api_setup-0.0.6 spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb
infinum_json_api_setup-0.0.5 spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb
infinum_json_api_setup-0.0.4 spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb
infinum_json_api_setup-0.0.3 spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb