Sha256: 341075b797e22c57fc18c652e853171cc97ad4b34b09f20cb77915c4b6f74860

Contents?: true

Size: 921 Bytes

Versions: 4

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

module RSpec
  module GraphqlMatchers
    module HaveAFieldMatchers
      class WithDeprecationReason
        def initialize(expected_reason)
          @expected_reason = expected_reason
        end

        def matches?(actual_field)
          @actual_reason = actual_field.deprecation_reason

          if @expected_reason.nil?
            !actual_field.deprecation_reason.nil?
          else
            actual_field.deprecation_reason == @expected_reason
          end
        end

        def failure_message
          message = "#{description}, but it was "
          message + (@actual_reason.nil? ? 'not deprecated' : "`#{@actual_reason}`")
        end

        def description
          if @expected_reason.nil?
            'with a deprecation reason'
          else
            "with deprecation reason `#{@expected_reason}`"
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-graphql_matchers-2.0.0.pre.rc.0 lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb
rspec-graphql_matchers-1.4.0 lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb
rspec-graphql_matchers-1.3.1 lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb
rspec-graphql_matchers-1.3.0 lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb