class RSpec::Mocks::AnyInstance::Chain

Private Class Methods

record(method_name) click to toggle source

@macro [attach] record

@method $1(*args, &block)
Records the `$1` message for playback against an instance that
invokes a method stubbed or mocked using `any_instance`.

@see RSpec::Mocks::MessageExpectation#$1
# File lib/rspec/mocks/any_instance/chain.rb, line 15
          def record(method_name)
            class_eval("              def #{method_name}(*args, &block)
                record(:#{method_name}, *args, &block)
              end
", __FILE__, __LINE__ + 1)
          end

Public Instance Methods

constrained_to_any_of?(*constraints) click to toggle source

@private

# File lib/rspec/mocks/any_instance/chain.rb, line 47
def constrained_to_any_of?(*constraints)
  constraints.any? do |constraint|
    messages.any? do |message|
      message.first.first == constraint
    end
  end
end
expectation_fulfilled!() click to toggle source

@private

# File lib/rspec/mocks/any_instance/chain.rb, line 56
def expectation_fulfilled!
  @expectation_fulfilled = true
end
playback!(instance) click to toggle source

@private

# File lib/rspec/mocks/any_instance/chain.rb, line 40
def playback!(instance)
  messages.inject(instance) do |_instance, message|
    _instance.__send__(*message.first, &message.last)
  end
end

Private Instance Methods

last_message() click to toggle source
# File lib/rspec/mocks/any_instance/chain.rb, line 66
def last_message
  messages.last.first.first unless messages.empty?
end
messages() click to toggle source
# File lib/rspec/mocks/any_instance/chain.rb, line 62
def messages
  @messages ||= []
end
record(rspec_method_name, *args, &block) click to toggle source
# File lib/rspec/mocks/any_instance/chain.rb, line 70
def record(rspec_method_name, *args, &block)
  verify_invocation_order(rspec_method_name, *args, &block)
  messages << [args.unshift(rspec_method_name), block]
  self
end