Class: RSpec::GraphqlMatchers::BeOfType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ BeOfType

Returns a new instance of BeOfType.



6
7
8
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 6

def initialize(expected)
  @expected = expected
end

Instance Attribute Details

#expectedObject (readonly)

Returns the value of attribute expected.



4
5
6
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 4

def expected
  @expected
end

#sampleObject (readonly)

Returns the value of attribute sample.



4
5
6
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 4

def sample
  @sample
end

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 20

def description
  "be of type '#{expected}'"
end

#failure_messageObject



15
16
17
18
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 15

def failure_message
  "expected field '#{field_name(sample)}' to be of type '#{expected}', " \
  "but it was '#{sample.type}'"
end

#matches?(actual_sample) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 10

def matches?(actual_sample)
  @sample = actual_sample
  sample.type.to_s == @expected.to_s
end