class GrapeEntityMatchers::DocumentMatcher::DocumentMatcher

Public Class Methods

new(documentable) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 10
def initialize(documentable)
  @expected_documentable = documentable
end

Public Instance Methods

default(default_value) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 39
def default(default_value)
  @default = default_value
  self
end
desc(desc_value) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 34
def desc(desc_value)
  @desc = desc_value
  self
end
description() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 14
def description
  "ensure that #{@subject} documents the #{@expected_documentable} exposure"
end
failure_message() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 54
def failure_message
  "#{@subject} didn't document #{@expected_documentable} "\
  "as expected: #{expected_documentation}, got #{match_documentation}"
end
failure_message_when_negated() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 59
def failure_message_when_negated
  message = "didn't expect #{@subject} to document #{@expected_documentable}"
  message << " with: #{expected_documentation}" unless expected_documentation.empty?
  message << ", got: #{actual_documentation}"
end
matches?(subject) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 18
def matches?(subject)
  @subject = subject

  has_documentation? && verify_documentation
end
required(required_value) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 29
def required(required_value)
  @required = required_value
  self
end
type(type_value) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 24
def type(type_value)
  @type = type_value
  self
end
values(values) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 44
def values(values)
  @values = values
  self
end
with(documentation) click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 49
def with(documentation)
  @documentation = documentation
  self
end

Private Instance Methods

actual_documentation() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 84
def actual_documentation
  exposure.documentation
end
expected_documentation() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 67
def expected_documentation
  @documentation ||
      {
        type: @type,
        desc: @desc,
        required: @required,
        default: @default,
        values: @values
      }.compact
end
exposure() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 92
def exposure
  exposures[@expected_documentable]
end
has_documentation?() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 88
def has_documentation?
  exposures.has_key?(@expected_documentable) && actual_documentation
end
match_documentation() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 78
def match_documentation
  if has_documentation?
    actual_documentation.slice(*expected_documentation.keys)
  end
end
verify_documentation() click to toggle source
# File lib/grape_entity_matchers/document_matcher.rb, line 96
def verify_documentation
  if @documentation
    @documentation == actual_documentation
  else
    expected_documentation == match_documentation
  end
end