Class: RSpec::GraphqlMatchers::HaveAFieldMatchers::WithDeprecationReason

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_reason) ⇒ WithDeprecationReason

Returns a new instance of WithDeprecationReason.



7
8
9
# File 'lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb', line 7

def initialize(expected_reason)
  @expected_reason = expected_reason
end

Instance Method Details

#descriptionObject



26
27
28
29
30
31
32
# File 'lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb', line 26

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

#failure_messageObject



21
22
23
24
# File 'lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb', line 21

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

#matches?(actual_field) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb', line 11

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