Sha256: af2a626c675c9493fcd66ad794b2c7b751c71940a6c037ba3d87cab623060e1a

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

module Shoulda
  module Matchers
    module Doublespeak
      # @private
      class DoubleCollection
        def initialize(klass)
          @klass = klass
          @doubles_by_method_name = {}
        end

        def register_stub(method_name)
          register_double(method_name, :stub)
        end

        def register_proxy(method_name)
          register_double(method_name, :proxy)
        end

        def activate
          doubles_by_method_name.each do |method_name, double|
            double.activate
          end
        end

        def deactivate
          doubles_by_method_name.each do |method_name, double|
            double.deactivate
          end
        end

        def calls_to(method_name)
          double = doubles_by_method_name[method_name]

          if double
            double.calls
          else
            []
          end
        end

        protected

        attr_reader :klass, :doubles_by_method_name

        def register_double(method_name, implementation_type)
          implementation =
            DoubleImplementationRegistry.find(implementation_type)
          double = Double.new(klass, method_name, implementation)
          doubles_by_method_name[method_name] = double
          double
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/lib/shoulda/matchers/doublespeak/double_collection.rb
shoulda-matchers-2.8.0 lib/shoulda/matchers/doublespeak/double_collection.rb
shoulda-matchers-2.8.0.rc2 lib/shoulda/matchers/doublespeak/double_collection.rb
shoulda-matchers-2.8.0.rc1 lib/shoulda/matchers/doublespeak/double_collection.rb
shoulda-matchers-2.7.0 lib/shoulda/matchers/doublespeak/double_collection.rb
shoulda-matchers-2.6.2 lib/shoulda/matchers/doublespeak/double_collection.rb