<commit_before>module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:

      # Ensures that the attribute can be set to the given value.
      #
      # Options:
      # * <tt>with_message</tt> - value the test expects to find in
      #   <tt>errors.on(:attribute)</tt>. Regexp or string. If omitted,
      #   the test looks for any errors in <tt>errors.on(:attribute)</tt>.
      #
      # Example:
      #   it { should_not allow_value('bad').for(:isbn) }
      #   it { should allow_value("isbn 1 2345 6789 0").for(:isbn) }
      #
      def allow_value(value)
        AllowValueMatcher.new(value)
      end

      class AllowValueMatcher # :nodoc:
        include Helpers

        def initialize(value)
          @value = value
        end

        def for(attribute)
          @attribute = attribute
          self
        end

        def with_message(message)
          @expected_message = message if message
          self
        end

        def matches?(instance)
          @instance = instance
          if Symbol === @expected_message
            @expected_message = default_error_message(@expected_message, :model_name => @instance.class.to_s.underscore, :attribute => @attribute)
          end
          @instance.send("#{@attribute}=", @value)
          !errors_match?
        end

        def failure_message
          "Did not expect #{expectation}, got error: #{@matched_error}"
        end

        def negative_failure_message
          "Expected #{expectation}, got #{error_description}"
        end

        def description
          "allow #{@attribute} to be set to #{@value.inspect}"
        end

        private

        def errors_match?
          if ! @instance.valid?
            @errors = errors_for_attribute(@instance, @attribute)
            @errors = [@errors] unless @errors.is_a?(Array)
            @expected_message ? (errors_match_regexp? || errors_match_string?) : (@errors.compact.any?)
          else
            @errors = []
            false
          end
        end

        def errors_for_attribute(instance, attribute)
          if instance.errors.respond_to?(:[])
            instance.errors[attribute]
          else
            instance.errors.on(attribute)
          end
        end

        def errors_match_regexp?
          if Regexp === @expected_message
            @matched_error = @errors.detect { |e| e =~ @expected_message }
            !@matched_error.nil?
          else
            false
          end
        end<commit_msg>remove a redundancy inside AllowValueMatcher<commit_after>module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:

      # Ensures that the attribute can be set to the given value.
      #
      # Options:
      # * <tt>with_message</tt> - value the test expects to find in
      #   <tt>errors.on(:attribute)</tt>. Regexp or string. If omitted,
      #   the test looks for any errors in <tt>errors.on(:attribute)</tt>.
      #
      # Example:
      #   it { should_not allow_value('bad').for(:isbn) }
      #   it { should allow_value("isbn 1 2345 6789 0").for(:isbn) }
      #
      def allow_value(value)
        AllowValueMatcher.new(value)
      end

      class AllowValueMatcher # :nodoc:
        include Helpers

        def initialize(value)
          @value = value
        end

        def for(attribute)
          @attribute = attribute
          self
        end

        def with_message(message)
          @expected_message = message if message
          self
        end

        def matches?(instance)
          @instance = instance
          if Symbol === @expected_message
            @expected_message = default_error_message(@expected_message, :model_name => @instance.class.to_s.underscore, :attribute => @attribute)
          end
          @instance.send("#{@attribute}=", @value)
          !errors_match?
        end

        def failure_message
          "Did not expect #{expectation}, got error: #{@matched_error}"
        end

        def negative_failure_message
          "Expected #{expectation}, got #{error_description}"
        end

        def description
          "allow #{@attribute} to be set to #{@value.inspect}"
        end

        private

        def errors_match?
          if ! @instance.valid?
            @errors = errors_for_attribute(@instance, @attribute)
            @errors = [@errors] unless @errors.is_a?(Array)
            @expected_message ? (errors_match_regexp? || errors_match_string?) : (@errors.compact.any?)
          else
            @errors = []
            false
          end
        end

        def errors_for_attribute(instance, attribute)
          if instance.errors.respond_to?(:[])
            instance.errors[attribute]
          else
            instance.errors.on(attribute)
          end
        end

        def errors_match_regexp?
          if Regexp === @expected_message
            @matched_error = @errors.detect { |e| e =~ @expected_message }
          else
            false
          end
        end
{'fraction_non_alphanumeric': 0.09637594583831142, 'fraction_numerical': 0.00398247710075667, 'mean_word_length': 1.8426711941143181, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1886152', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1336, 'n_words': 346}