Class: RSpec::Mocks::AnyInstance::Chain

Inherits:
Object
  • Object
show all
Includes:
Customizations
Defined in:
lib/rspec/mocks/any_instance/chain.rb

Direct Known Subclasses

ExpectationChain, StubChain

Defined Under Namespace

Modules: Customizations

Instance Method Summary (collapse)

Methods included from Customizations

#and_call_original, #and_raise, #and_return, #and_throw, #and_yield, #any_number_of_times, #at_least, #at_most, #exactly, #once, record, #times, #twice, #with

Constructor Details

- (Chain) initialize(recorder, *args, &block)

Returns a new instance of Chain



7
8
9
10
11
# File 'lib/rspec/mocks/any_instance/chain.rb', line 7

def initialize(recorder, *args, &block)
  @recorder          = recorder
  @expectation_args  = args
  @expectation_block = block
end

Instance Method Details

- (Boolean) constrained_to_any_of?(*constraints)

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/rspec/mocks/any_instance/chain.rb', line 58

def constrained_to_any_of?(*constraints)
  constraints.any? do |constraint|
    messages.any? do |message|
      message.first.first == constraint
    end
  end
end

- (Object) expectation_fulfilled!



67
68
69
# File 'lib/rspec/mocks/any_instance/chain.rb', line 67

def expectation_fulfilled!
  @expectation_fulfilled = true
end

- (Object) never



71
72
73
74
# File 'lib/rspec/mocks/any_instance/chain.rb', line 71

def never
  ErrorGenerator.raise_double_negation_error("expect_any_instance_of(MyClass)") if negated?
  super
end

- (Object) playback!(instance)



50
51
52
53
54
55
# File 'lib/rspec/mocks/any_instance/chain.rb', line 50

def playback!(instance)
  message_expectation = create_message_expectation_on(instance)
  messages.inject(message_expectation) do |object, message|
    object.__send__(*message.first, &message.last)
  end
end