class RSpec::Raml::Matchers::MatchRamlBody

Public Class Methods

new(*) click to toggle source
Calls superclass method RSpec::Raml::Matchers::Abstract::new
# File lib/rspec/raml/matchers/match_raml_body.rb, line 8
def initialize(*)
  super
  @excludes = []
  @differ   = RSpec::Support::Differ.new(color: true)
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 14
def description
  'match RAML body'
end
except(*values)
Alias for: exclude
exclude(*values) click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 18
def exclude(*values)
  @excludes += values
  self
end
Also aliased as: except
failure_message() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 24
def failure_message
  diff = @differ.diff_as_object(actual, expected)
  "expected response bodies to match:#{diff}"
end
failure_message_when_negated() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 29
def failure_message_when_negated
  "expected response bodies not to match"
end

Private Instance Methods

actual() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 39
def actual
  @actual ||= JSON.parse(response.body)
end
exclusion_filter() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 50
def exclusion_filter
  ExclusionFilter.new(@excludes)
end
expected() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 43
def expected
  @expected ||= begin
    example = raml.bodies.fetch(content_type).example
    exclusion_filter.filter JSON.parse(example)
  end
end
matches_raml?() click to toggle source
# File lib/rspec/raml/matchers/match_raml_body.rb, line 35
def matches_raml?
  RSpec::Support::FuzzyMatcher.values_match?(expected, actual)
end