<commit_before>module Spec
  module Api
    class Mock
      # Remove all methods so they can be mocked too
      (public_instance_methods - ['__id__', '__send__', 'nil?']).each do |m|
        undef_method m
      end

      # Creates a new mock with a +name+ (that will be used in error messages only)
      # Options:
      # * <tt>:null_object</tt> - if true, the mock object acts as a forgiving null object allowing any message to be sent to it.
      def initialize(name, options={})
        @name = name
        @options = DEFAULT_OPTIONS.dup.merge(options)
        @expectations = []
        @expectation_ordering = OrderGroup.new
      end
      
      def should_receive(sym, &block)
        add MessageExpectation, caller(1)[0], sym, &block
      end
      
      def should_not_receive(sym, &block)
        add NegativeMessageExpectation, caller(1)[0], sym, &block
      end
      
      def add(klass, expected_from, sym, &block)
        expectation = klass.send(:new, @name, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
        @expectations << expectation
        expectation
      end

      def __verify #:nodoc:
        @expectations.each do |expectation|
          expectation.verify_messages_received
        end
      end

      def method_missing(sym, *args, &block)
        if expectation = find_matching_expectation(sym, *args)
          expectation.invoke(args, block)
        else
          begin
            # act as null object if method is missing and we ignore them. return value too!
            @options[:null_object] ? self : super(sym, *args, &block)
          rescue NoMethodError
            arg_message = args.collect{|arg| "<#{arg}:#{arg.class.name}>"}.join(", ")
            Kernel::raise Spec::Api::MockExpectationError, "Mock '#{@name}' received unexpected message '#{sym}' with [#{arg_message}]"
          end
        end
      end

    private

      DEFAULT_OPTIONS = {
        :null_object => false
      }
      
      def find_matching_expectation(sym, *args)<commit_msg>better naming related to mock.should_not_receive<commit_after>module Spec
  module Api
    class Mock
      # Remove all methods so they can be mocked too
      (public_instance_methods - ['__id__', '__send__', 'nil?']).each do |m|
        undef_method m
      end

      # Creates a new mock with a +name+ (that will be used in error messages only)
      # Options:
      # * <tt>:null_object</tt> - if true, the mock object acts as a forgiving null object allowing any message to be sent to it.
      def initialize(name, options={})
        @name = name
        @options = DEFAULT_OPTIONS.dup.merge(options)
        @expectations = []
        @expectation_ordering = OrderGroup.new
      end
      
      def should_receive(sym, &block)
        add MessageExpectation, caller(1)[0], sym, &block
      end
      
      def should_not_receive(sym, &block)
        add NegativeMessageExpectation, caller(1)[0], sym, &block
      end
      
      def add(expectation_class, expected_from, sym, &block)
        expectation = expectation_class.send(:new, @name, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
        @expectations << expectation
        expectation
      end

      def __verify #:nodoc:
        @expectations.each do |expectation|
          expectation.verify_messages_received
        end
      end

      def method_missing(sym, *args, &block)
        if expectation = find_matching_expectation(sym, *args)
          expectation.invoke(args, block)
        else
          begin
            # act as null object if method is missing and we ignore them. return value too!
            @options[:null_object] ? self : super(sym, *args, &block)
          rescue NoMethodError
            arg_message = args.collect{|arg| "<#{arg}:#{arg.class.name}>"}.join(", ")
            Kernel::raise Spec::Api::MockExpectationError, "Mock '#{@name}' received unexpected message '#{sym}' with [#{arg_message}]"
          end
        end
      end

    private

      DEFAULT_OPTIONS = {
        :null_object => false
      }
      
      def find_matching_expectation(sym, *args)
{'fraction_non_alphanumeric': 0.09963811821471652, 'fraction_numerical': 0.0019300361881785283, 'mean_word_length': 2.3817292006525284, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4481440', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1164, 'n_words': 349}