Sha256: 83f1d2e7d495d618636bb0a8c6a25fe6b40dcd5ee0e90fede897a82babc9a0d7

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require "rspec/matchers"
require "rspec/expectations"

module NulogyGraphqlApi
  module GraphqlMatchers
    RSpec::Matchers.define :have_graphql_data do |expected_data|
      match do |graphql_response|
        @expected_response = { data: expected_data }
        expect(graphql_response).to match(@expected_response)
      end

      failure_message do |actual_response|
        <<~MSG
          expected: #{@expected_response.pretty_inspect}

          got: #{actual_response.pretty_inspect}
        MSG
      end
    end

    RSpec::Matchers.define :have_graphql_error do |message|
      match do |actual_response|
        expect(actual_response.fetch(:errors, nil)).to contain_exactly(a_hash_including(
          message: include(message)
        ))
      end
    end

    RSpec::Matchers.define :have_network_error do |message, error_extensions = {}|
      match do |actual_response|
        expect(actual_response).to match({
          data: {},
          errors: [{ message: message }.merge(error_extensions)]
        })
      end
    end

    RSpec::Matchers.define :include_graphql_error do |message|
      match do |actual_response|
        expect(actual_response.fetch(:errors, nil)).to include(a_hash_including(
          message: include(message)
        ))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nulogy_graphql_api-4.3.0 lib/nulogy_graphql_api/rspec/graphql_matchers.rb
nulogy_graphql_api-4.2.0 lib/nulogy_graphql_api/rspec/graphql_matchers.rb
nulogy_graphql_api-4.0.0 lib/nulogy_graphql_api/rspec/graphql_matchers.rb
nulogy_graphql_api-3.0.1 lib/nulogy_graphql_api/rspec/graphql_matchers.rb