<commit_before>require 'spec_helper'

module Rspec
  module Mocks

    # We expect our original method to be stashed like this:
    #
    # class Rspec::Mocks::FooBar
    #   def self.foo(*args, &block)
    #     __mock_proxy.message_received(:foo, *args, &block)
    #   end
    #
    #   def self.obfuscated_by_rspec_mocks__foo(arg)
    #     :original_value
    #   end
    # end

    # Yet, we end up with the proxy method being stashed when multiple
    # expectations are added to the same method:
    #
    # class Rspec::Mocks::FooBar
    #   def self.foo(*args, &block)
    #     __mock_proxy.message_received(:foo, *args, &block)
    #   end
    #
    #   def self.obfuscated_by_rspec_mocks__foo(*args, &block)
    #     __mock_proxy.message_received(:foo, *args, &block)
    #   end
    # end

    class FooBar
      def self.foo(arg)
        :original_value
      end
    end

    describe "only stashing the original method" do
      # Fix to avoid stashing the proxy method once the original method has already been stashed.
      # Having multiple stubs or expectations on the same method would result in the
      # original method being completely lost if it did not check if it was already stashed.
      it "should keep the original method intact after multiple expectations are added on the same method" do
        FooBar.should_receive(:foo).with(:fizbaz).and_return(:wowwow)
        FooBar.should_receive(:foo).with(:bazbar).and_return(:okay)

        FooBar.foo(:fizbaz)
        FooBar.foo(:bazbar)
        FooBar.rspec_verify

        FooBar.rspec_reset
        FooBar.foo(:yeah).should equal(:original_value)
      end<commit_msg>the example name speaks for itself<commit_after>require 'spec_helper'

module Rspec
  module Mocks

    describe "only stashing the original method" do
      let(:klass) do
        Class.new do
          def self.foo(arg)
            :original_value
          end
        end
      end
      it "should keep the original method intact after multiple expectations are added on the same method" do
        klass.should_receive(:foo).with(:fizbaz).and_return(:wowwow)
        klass.should_receive(:foo).with(:bazbar).and_return(:okay)

        klass.foo(:fizbaz)
        klass.foo(:bazbar)
        klass.rspec_verify

        klass.rspec_reset
        klass.foo(:yeah).should equal(:original_value)
      end
{'fraction_non_alphanumeric': 0.08432203389830509, 'fraction_numerical': 0.0, 'mean_word_length': 2.6156202143950997, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7125371', 'n_tokens_mistral': 741, 'n_tokens_neox': 714, 'n_words': 202}