Class: RSpec::Matchers::DelegateMatcher::Delegate

Inherits:
Object
  • Object
show all
Includes:
Block
Defined in:
lib/delegate_matcher/delegate.rb

Direct Known Subclasses

NilDelegate, StubDelegate

Instance Attribute Summary collapse

Attributes included from Block

#block

Instance Method Summary collapse

Methods included from Block

#block_source

Constructor Details

#initialize(expected, to) ⇒ Delegate

Returns a new instance of Delegate.



11
12
13
14
15
# File 'lib/delegate_matcher/delegate.rb', line 11

def initialize(expected, to)
  self.expected = expected
  self.to       = to
  self.received = false
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



9
10
11
# File 'lib/delegate_matcher/delegate.rb', line 9

def args
  @args
end

#receivedObject

Returns the value of attribute received.



9
10
11
# File 'lib/delegate_matcher/delegate.rb', line 9

def received
  @received
end

#toObject

Returns the value of attribute to.



9
10
11
# File 'lib/delegate_matcher/delegate.rb', line 9

def to
  @to
end

Instance Method Details

#argument_descriptionObject



36
37
38
# File 'lib/delegate_matcher/delegate.rb', line 36

def argument_description
  args ? "(#{args.map(&:inspect).join(', ')})" : ''
end

#receiverObject

rubocop:disable Metrics/AbcSize



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/delegate_matcher/delegate.rb', line 18

def receiver
  klass = subject.class
  @receiver ||= case
                when a_class_variable?
                  klass.class_variable_get(name)
                when an_instance_variable?
                  subject.instance_variable_get(name)
                when a_constant?
                  klass.const_get(name)
                when a_method?
                  subject.send(name)
                when a_reference?
                  subject.instance_eval(name)
                else # is an object
                  to
                end
end