<commit_before>module RR
  module DoubleDefinitions
    class DoubleDefinition #:nodoc:
      class << self
        def register_strategy_class(strategy_class, method_name)
          class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
          def #{method_name}(subject=DoubleDefinitionCreator::NO_SUBJECT, method_name=nil, &definition_eval_block)
            ChildDoubleDefinitionCreator.new(self).#{method_name}(subject, method_name, &definition_eval_block)
          end
          CLASS

          class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
          def #{method_name}!(method_name=nil, &definition_eval_block)
            ChildDoubleDefinitionCreator.new(self).#{method_name}!(method_name, &definition_eval_block)
          end
          CLASS
        end
      end

      ORIGINAL_METHOD = Object.new
      attr_accessor(
        :argument_expectation,
        :times_matcher,
        :implementation,
        :after_call_proc,
        :yields_value,
        :double,
        :double_definition_creator,
        :subject
      )

      include Space::Reader

      def initialize(double_definition_creator, subject)
        @implementation = nil
        @argument_expectation = nil
        @times_matcher = nil
        @after_call_proc = nil
        @yields_value = nil
        @double_definition_creator = double_definition_creator
        @subject = subject
      end
      
      attr_reader :argument_expectation

      def root_subject
        double_definition_creator.root_subject
      end
      
      module ArgumentDefinitionConstructionMethods
        # Double#with sets the expectation that the Double will receive
        # the passed in arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with(1, 2) {:return_value}        
        def with(*args, &return_value_block)
          @argument_expectation = Expectations::ArgumentEqualityExpectation.new(*args)
          install_method_callback return_value_block
          self
        end

        # Double#with_any_args sets the expectation that the Double can receive
        # any arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with_any_args {:return_value}
        def with_any_args(&return_value_block)
          @argument_expectation = Expectations::AnyArgumentExpectation.new
          install_method_callback return_value_block
          self
        end

        # Double#with_no_args sets the expectation that the Double will receive
        # no arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with_no_args {:return_value}
        def with_no_args(&return_value_block)
          @argument_expectation = Expectations::ArgumentEqualityExpectation.new()
          install_method_callback return_value_block
          self
        end        
      end
      include ArgumentDefinitionConstructionMethods

      module TimesDefinitionConstructionMethods
        # Double#never sets the expectation that the Double will never be
        # called.
        #
        # This method does not accept a block because it will never be called.
        #
        #   mock(subject).method_name.never
        def never
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(0)
          self
        end

        # Double#once sets the expectation that the Double will be called
        # 1 time.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.once {:return_value}
        def once(&return_value_block)
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(1)
          install_method_callback return_value_block
          self
        end

        # Double#twice sets the expectation that the Double will be called
        # 2 times.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.twice {:return_value}        
        def twice(&return_value_block)
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(2)
          install_method_callback return_value_block
          self
        end

        # Double#at_least sets the expectation that the Double
        # will be called at least n times.
        # It works by creating a TimesCalledExpectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.at_least(4) {:return_value}
        def at_least(number, &return_value_block)
          @times_matcher = TimesCalledMatchers::AtLeastMatcher.new(number)
          install_method_callback return_value_block
          self
        end

        # Double#at_most allows sets the expectation that the Double
        # will be called at most n times.
        # It works by creating a TimesCalledExpectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.at_most(4) {:return_value}        
        def at_most(number, &return_value_block)
          @times_matcher = TimesCalledMatchers::AtMostMatcher.new(number)
          install_method_callback return_value_block
          self
        end

        # Double#any_number_of_times sets an that the Double will be called
        # any number of times. This effectively removes the times called expectation
        # from the Doublen
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.any_number_of_times        
        def any_number_of_times(&return_value_block)
          @times_matcher = TimesCalledMatchers::AnyTimesMatcher.new
          install_method_callback return_value_block
          self
        end

        # Double#times creates an TimesCalledExpectation of the passed
        # in number.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.times(4) {:return_value}        
        def times(matcher_value, &return_value_block)
          @times_matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value)
          install_method_callback return_value_block
          self
        end
      end
      include TimesDefinitionConstructionMethods

      module DefinitionConstructionMethods
        # Double#ordered sets the Double to have an ordered
        # expectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.ordered {return_value}
        def ordered(&return_value_block)
          raise(
            Errors::DoubleDefinitionError,
            "Double Definitions must have a dedicated Double to be ordered. " <<
            "For example, using instance_of does not allow ordered to be used. " <<
            "proxy the class's #new method instead."
          ) unless @double<commit_msg>added alias: any_times for any_number_of_times<commit_after>module RR
  module DoubleDefinitions
    class DoubleDefinition #:nodoc:
      class << self
        def register_strategy_class(strategy_class, method_name)
          class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
          def #{method_name}(subject=DoubleDefinitionCreator::NO_SUBJECT, method_name=nil, &definition_eval_block)
            ChildDoubleDefinitionCreator.new(self).#{method_name}(subject, method_name, &definition_eval_block)
          end
          CLASS

          class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
          def #{method_name}!(method_name=nil, &definition_eval_block)
            ChildDoubleDefinitionCreator.new(self).#{method_name}!(method_name, &definition_eval_block)
          end
          CLASS
        end
      end

      ORIGINAL_METHOD = Object.new
      attr_accessor(
        :argument_expectation,
        :times_matcher,
        :implementation,
        :after_call_proc,
        :yields_value,
        :double,
        :double_definition_creator,
        :subject
      )

      include Space::Reader

      def initialize(double_definition_creator, subject)
        @implementation = nil
        @argument_expectation = nil
        @times_matcher = nil
        @after_call_proc = nil
        @yields_value = nil
        @double_definition_creator = double_definition_creator
        @subject = subject
      end
      
      attr_reader :argument_expectation

      def root_subject
        double_definition_creator.root_subject
      end
      
      module ArgumentDefinitionConstructionMethods
        # Double#with sets the expectation that the Double will receive
        # the passed in arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with(1, 2) {:return_value}        
        def with(*args, &return_value_block)
          @argument_expectation = Expectations::ArgumentEqualityExpectation.new(*args)
          install_method_callback return_value_block
          self
        end

        # Double#with_any_args sets the expectation that the Double can receive
        # any arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with_any_args {:return_value}
        def with_any_args(&return_value_block)
          @argument_expectation = Expectations::AnyArgumentExpectation.new
          install_method_callback return_value_block
          self
        end

        # Double#with_no_args sets the expectation that the Double will receive
        # no arguments.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.with_no_args {:return_value}
        def with_no_args(&return_value_block)
          @argument_expectation = Expectations::ArgumentEqualityExpectation.new()
          install_method_callback return_value_block
          self
        end        
      end
      include ArgumentDefinitionConstructionMethods

      module TimesDefinitionConstructionMethods
        # Double#never sets the expectation that the Double will never be
        # called.
        #
        # This method does not accept a block because it will never be called.
        #
        #   mock(subject).method_name.never
        def never
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(0)
          self
        end

        # Double#once sets the expectation that the Double will be called
        # 1 time.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.once {:return_value}
        def once(&return_value_block)
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(1)
          install_method_callback return_value_block
          self
        end

        # Double#twice sets the expectation that the Double will be called
        # 2 times.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.twice {:return_value}        
        def twice(&return_value_block)
          @times_matcher = TimesCalledMatchers::IntegerMatcher.new(2)
          install_method_callback return_value_block
          self
        end

        # Double#at_least sets the expectation that the Double
        # will be called at least n times.
        # It works by creating a TimesCalledExpectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.at_least(4) {:return_value}
        def at_least(number, &return_value_block)
          @times_matcher = TimesCalledMatchers::AtLeastMatcher.new(number)
          install_method_callback return_value_block
          self
        end

        # Double#at_most allows sets the expectation that the Double
        # will be called at most n times.
        # It works by creating a TimesCalledExpectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.at_most(4) {:return_value}        
        def at_most(number, &return_value_block)
          @times_matcher = TimesCalledMatchers::AtMostMatcher.new(number)
          install_method_callback return_value_block
          self
        end

        # Double#any_number_of_times sets an that the Double will be called
        # any number of times. This effectively removes the times called expectation
        # from the Doublen
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.any_number_of_times        
        def any_number_of_times(&return_value_block)
          @times_matcher = TimesCalledMatchers::AnyTimesMatcher.new
          install_method_callback return_value_block
          self
        end
        alias_method :any_times, :any_number_of_times

        # Double#times creates an TimesCalledExpectation of the passed
        # in number.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.times(4) {:return_value}        
        def times(matcher_value, &return_value_block)
          @times_matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value)
          install_method_callback return_value_block
          self
        end
      end
      include TimesDefinitionConstructionMethods

      module DefinitionConstructionMethods
        # Double#ordered sets the Double to have an ordered
        # expectation.
        #
        # Passing in a block sets the return value.
        #
        #   mock(subject).method_name.ordered {return_value}
        def ordered(&return_value_block)
          raise(
            Errors::DoubleDefinitionError,
            "Double Definitions must have a dedicated Double to be ordered. " <<
            "For example, using instance_of does not allow ordered to be used. " <<
            "proxy the class's #new method instead."
          ) unless @double
{'fraction_non_alphanumeric': 0.06104129263913824, 'fraction_numerical': 0.0017235188509874327, 'mean_word_length': 2.198438217730822, 'pattern_counts': {'":': 0, '<': 23, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '245243', 'n_tokens_mistral': 3680, 'n_tokens_neox': 3611, 'n_words': 942}