Sha256: 9f41cb0f15b3a6550019310368cd36a8bea534bd1ecaeb4c8b7d40b2700b35bb

Contents?: true

Size: 614 Bytes

Versions: 3

Compression:

Stored size: 614 Bytes

Contents

module RSpec
  module Siren
    module Matchers
      class HasLink
        def initialize(expected_rel)
          @expected_rel = expected_rel
        end

        def matches?(target)
          @target = target
          link = safe_links.detect { |l| l[:rel].include?(@expected_rel) }

          !!link
        end

        def description
          "have a link with rel '#{@expected_rel}'"
        end

        def failure_message
          "has no link with rel '#{@expected_rel}'"
        end

        private

        def safe_links
          Array(@target[:links])
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-siren-1.1.0 lib/rspec/siren/matchers/has_link.rb
rspec-siren-1.0.1 lib/rspec/siren/matchers/has_link.rb
rspec-siren-1.0.0 lib/rspec/siren/matchers/has_link.rb