<commit_before>module RSpec
  module Hal
    module Matchers

      # Example
      #
      #     expect(doc).to have_property("name")
      #     expect(doc).to have_property("search", matching("Alice"))
      #
      class HavePropertyMatcher
        include HalMatcherHelpers

        def initialize(property_name, expected=NullMatcher)
          @prop_name = property_name
          @expected = expected
        end

        def matches?(jsonish)
          repr = parse(jsonish)

          repr.property?(prop_name) &&
            expected === repr.property(prop_name){ nil }
        end

        def failure_message
          but_clause = if outcome == :no_templates
                         "found only non-templated links"
                       else
                         "found none"
                       end
          expected_clause = if expected != NullMatcher && expected.respond_to?(:description)
                              expected.description
                            elsif expected != NullMatcher
                              "matching #{expected}"
                            else
                              "to exist"
                            end

          "Expected templated `#{link_rel}` link #{expected_clause} but #{but_clause}"
        end
        alias_method :failure_message_for_should, :failure_message

        def failure_message_when_negated
          "Expected `#{link_rel}` link to be absent or not templated"
        end
        alias_method :failure_message_for_should_not, :failure_message_when_negated

        def description
          "have property `#{prop_name}` #{@expected.description}"
        end


        def matching(expected)
          expected = if expected.respond_to? :description
                       expected
                     else
                       RSpec::Matchers::BuiltIn::Match.new(expected)
                     end
          self.class.new(prop_name, expected)
        end
        alias_method :that_is, :matching

        def including(expected)
          self.class.new(prop_name, RSpec::Matchers::BuiltIn::Include.new(expected))
        end

        protected
<commit_msg>use matcherize helper function<commit_after>module RSpec
  module Hal
    module Matchers

      # Example
      #
      #     expect(doc).to have_property("name")
      #     expect(doc).to have_property("search", matching("Alice"))
      #
      class HavePropertyMatcher
        include HalMatcherHelpers

        def initialize(property_name, expected=NullMatcher)
          @prop_name = property_name
          @expected = expected
        end

        def matches?(jsonish)
          repr = parse(jsonish)

          repr.property?(prop_name) &&
            expected === repr.property(prop_name){ nil }
        end

        def failure_message
          but_clause = if outcome == :no_templates
                         "found only non-templated links"
                       else
                         "found none"
                       end
          expected_clause = if expected != NullMatcher && expected.respond_to?(:description)
                              expected.description
                            elsif expected != NullMatcher
                              "matching #{expected}"
                            else
                              "to exist"
                            end

          "Expected templated `#{link_rel}` link #{expected_clause} but #{but_clause}"
        end
        alias_method :failure_message_for_should, :failure_message

        def failure_message_when_negated
          "Expected `#{link_rel}` link to be absent or not templated"
        end
        alias_method :failure_message_for_should_not, :failure_message_when_negated

        def description
          "have property `#{prop_name}` #{@expected.description}"
        end


        def matching(expected)
          self.class.new(prop_name, matcherize(expected))
        end
        alias_method :that_is, :matching

        def including(expected)
          self.class.new(prop_name, RSpec::Matchers::BuiltIn::Include.new(expected))
        end

        protected

{'fraction_non_alphanumeric': 0.07495782116172572, 'fraction_numerical': 0.0, 'mean_word_length': 1.5888958203368684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4251', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1006, 'n_words': 229}