Class: AgnosticBackend::RSpec::Matchers::DefineIndexField

Inherits:
Object
  • Object
show all
Defined in:
lib/agnostic_backend/rspec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, for_index: nil, type: nil, **expected_custom_attributes) ⇒ DefineIndexField

Returns a new instance of DefineIndexField.



19
20
21
22
23
24
# File 'lib/agnostic_backend/rspec/matchers.rb', line 19

def initialize(name, for_index: nil, type: nil, **expected_custom_attributes)
  @name = name
  @for_index = for_index
  @type = type
  @expected_custom_attributes = expected_custom_attributes
end

Instance Method Details

#descriptionObject



36
37
38
# File 'lib/agnostic_backend/rspec/matchers.rb', line 36

def description
  expectation_message
end

#failure_messageObject



40
41
42
# File 'lib/agnostic_backend/rspec/matchers.rb', line 40

def failure_message
  "expected to #{expectation_message}"
end

#matches?(klass) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/agnostic_backend/rspec/matchers.rb', line 26

def matches?(klass)
  @for_index ||= klass.index_name
  manager = klass.index_content_manager(@for_index)
  manager.nil? and return false
  field = manager.contents[@name.to_s]
  field.nil? and return false
  type_matches?(field, @type) &&
    custom_attributes_match?(field, @expected_custom_attributes) rescue false
end