class RSpec::Matchers::DelegateMatcher::Delegate

Attributes

args[RW]
block[W]
expected[RW]
received[RW]
to[RW]

Public Class Methods

new(expected, to) click to toggle source
# File lib/delegate_matcher/delegate.rb, line 11
def initialize(expected, to)
  self.expected = expected
  self.to       = to
  self.received = false
end

Public Instance Methods

argument_description() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 36
def argument_description
  args ? "(#{args.map(&:inspect).join(', ')})" : ''
end
receiver() click to toggle source

rubocop:disable Metrics/AbcSize

# 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

Private Instance Methods

a_class_variable?() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 53
def a_class_variable?
  a_reference? && name.start_with?('@@')
end
a_constant?() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 61
def a_constant?
  a_reference? && name =~ /^[A-Z]/
end
a_method?() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 65
def a_method?
  a_reference? && subject.respond_to?(name, true)
end
a_reference?() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 69
def a_reference?
  to.is_a?(String) || to.is_a?(Symbol)
end
an_instance_variable?() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 57
def an_instance_variable?
  a_reference? && name.start_with?('@')
end
name() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 49
def name
  to.to_s
end
subject() click to toggle source
# File lib/delegate_matcher/delegate.rb, line 45
def subject
  expected.subject
end