Sha256: 8874511eeb6a61549c42645b292dec07472371ad64e5e21d57a3967070e7a313

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module RSpec
  module Siren
    module MatchersSpecHelper
      def match!
        matcher.matches?(siren_hash)
      end

      def siren_hash
        {
          class: siren_classes,
          links: siren_links,
          entities: siren_entities,
          properties: siren_properties,
        }
      end

      def siren_classes
        [ "my-class" ]
      end

      def siren_links
        [
          { rel: ["my-link"], href: "http://example.com" },
        ]
      end

      def siren_entities
        [
          { class: ["my-entity"], href: "http://example.com" },
          { class: ["my-entity"], href: "http://example.com" },
        ]
      end

      def siren_properties
        {
          someProperty: "someValue"
        }
      end

      class MatchSirenMatcher < Struct.new(:siren_hash)
        def matches?(matcher)
          @matcher = matcher
          matcher.matches?(siren_hash) == true
        end

        def description
          "match"
        end

        def failure_message
          "expected to match but did not match." \
            " original failure message is: " \
            "#{@matcher.failure_message.inspect}"
        end

        def failure_message_when_negated
          "expected to not match but matched"
        end
      end

      def match_siren
        MatchSirenMatcher.new(siren_hash)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-siren-1.0.1 spec/support/matchers_spec_helper.rb
rspec-siren-1.0.0 spec/support/matchers_spec_helper.rb