Sha256: db0942b560c1a1ca00462ec05f0568a1f98bae1af29c315b02723085e7211167

Contents?: true

Size: 1.22 KB

Versions: 128

Compression:

Stored size: 1.22 KB

Contents

require 'rspec/mocks/any_instance/chain'
require 'rspec/mocks/any_instance/message_chains'
require 'rspec/mocks/any_instance/recorder'

module RSpec
  module Mocks
    module AnyInstance
      # Used to set stubs and message expectations on any instance of a given
      # class. Returns a [Recorder](Recorder), which records messages like
      # `stub` and `should_receive` for later playback on instances of the
      # class.
      #
      # @example
      #
      #     Car.any_instance.should_receive(:go)
      #     race = Race.new
      #     race.cars << Car.new
      #     race.go # assuming this delegates to all of its cars
      #             # this example would pass
      #
      #     Account.any_instance.stub(:balance) { Money.new(:USD, 25) }
      #     Account.new.balance # => Money.new(:USD, 25))
      #
      # @return [Recorder]
      def any_instance
        RSpec::Mocks::space.add(self)
        __recorder
      end
      
      # @private
      def rspec_verify
        __recorder.verify
        super
      ensure
        __recorder.stop_all_observation!
        @__recorder = nil
      end

      # @private
      def __recorder
        @__recorder ||= AnyInstance::Recorder.new(self)
      end
    end
  end
end

Version data entries

128 entries across 76 versions & 9 rubygems

Version Path
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.8 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.8 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.7 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.7 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.6 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.6 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.5 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.5 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.4 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.4 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.3 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.3 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.2 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.2 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.1 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.1 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb
classiccms-0.3.0 vendor/bundle/gems/rspec-mocks-2.9.0/lib/rspec/mocks/any_instance.rb
classiccms-0.3.0 vendor/bundle/gems/rspec-mocks-2.10.1/lib/rspec/mocks/any_instance.rb