module RSpec::Hal::Matchers::HalMatcherHelpers

Constants

NullMatcher

A matcher that always matches. Useful for avoiding special cases in value testing logic.

Attributes

repr[R]

Public Instance Methods

matcher?(obj) click to toggle source

Returns true if object is an RSpec matcher

# File lib/rspec/hal/matchers/hal_matcher_helpers.rb, line 83
def matcher?(obj)
  obj.respond_to?(:matches?) and (obj.respond_to?(:failure_message) or
                                  obj.respond_to?(:failure_message_for_should))
end
matcherize(expected) click to toggle source

Returns ‘expected` coerced into an RSpec matcher

# File lib/rspec/hal/matchers/hal_matcher_helpers.rb, line 70
def matcherize(expected)
  if matcher? expected
    expected

  elsif expected.respond_to? :===
    RSpec::Matchers::BuiltIn::Match.new(expected)

  else
    RSpec::Matchers::BuiltIn::Eq.new(expected)
  end
end
parse(jsonish) click to toggle source

Returns HalClient::Representation of the provided jsonish thing.

jsonish - A HAL document (as a string or pre-parsed hash) or

an object that can be converted into one via its `#to_hal`
or `#to_json` methods.
# File lib/rspec/hal/matchers/hal_matcher_helpers.rb, line 55
def parse(jsonish)
  json = if jsonish.kind_of? String
           jsonish

         elsif jsonish.respond_to? :to_hal
           jsonish.to_hal

         else jsonish.respond_to? :to_json
           jsonish.to_json
         end

  HalClient::Representation.new(parsed_json: MultiJson.load(json))
end
repr=(jsonish) click to toggle source
# File lib/rspec/hal/matchers/hal_matcher_helpers.rb, line 31
def repr=(jsonish)
  @repr = parse jsonish
end
sentencize(*clauses) click to toggle source

Returns string composed of the specified clauses with proper spacing between them. Empty and nil clauses are ignored.

# File lib/rspec/hal/matchers/hal_matcher_helpers.rb, line 40
def sentencize(*clauses)
  clauses
    .flatten
    .compact
    .reject(&:empty?)
    .map(&:strip)
    .join(" ")
end