Sha256: 6ec09056a6f9cfc58aa8aaae4a35b567a4d6a0c26a186e44b03ee7366d7662fd

Contents?: true

Size: 1.81 KB

Versions: 189

Compression:

Stored size: 1.81 KB

Contents

module RSpec
  module Mocks
    module AnyInstance
      # @private
      class MessageChains < Hash
        def initialize
          super {|h,k| h[k] = []}
        end

        # @private
        def add(method_name, chain)
          self[method_name] << chain
          chain
        end

        # @private
        def remove_stub_chains_for!(method_name)
          self[method_name].reject! {|chain| chain.is_a?(StubChain)}
        end

        # @private
        def has_expectation?(method_name)
          self[method_name].find {|chain| chain.is_a?(ExpectationChain)}
        end

        # @private
        def all_expectations_fulfilled?
          all? {|method_name, chains| chains.all? {|chain| chain.expectation_fulfilled?}}
        end

        # @private
        def unfulfilled_expectations
          map do |method_name, chains|
            method_name.to_s if chains.last.is_a?(ExpectationChain) unless chains.last.expectation_fulfilled?
          end.compact
        end

        # @private
        def received_expected_message!(method_name)
          self[method_name].each {|chain| chain.expectation_fulfilled!}
        end

        # @private
        def playback!(instance, method_name)
          raise_if_second_instance_to_receive_message(instance)
          self[method_name].each {|chain| chain.playback!(instance)}
        end

        private

        def raise_if_second_instance_to_receive_message(instance)
          @instance_with_expectation ||= instance if instance.is_a?(ExpectationChain)
          if instance.is_a?(ExpectationChain) && !@instance_with_expectation.equal?(instance)
            raise RSpec::Mocks::MockExpectationError, "Exactly one instance should have received the following message(s) but didn't: #{unfulfilled_expectations.sort.join(', ')}"
          end
        end
      end
    end
  end
end

Version data entries

189 entries across 137 versions & 25 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance/message_chains.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance/message_chains.rb
rspec-mocks-2.99.4 lib/rspec/mocks/any_instance/message_chains.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb
rspec-mocks-2.99.3 lib/rspec/mocks/any_instance/message_chains.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-mocks-2.13.0/lib/rspec/mocks/any_instance/message_chains.rb
rspec-mocks-2.99.2 lib/rspec/mocks/any_instance/message_chains.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/lib/rspec/mocks/any_instance/message_chains.rb