class RSpec::Matchers::DelegateMatcher::NilDelegate
Public Class Methods
new(expected, to, &block)
click to toggle source
Calls superclass method
RSpec::Matchers::DelegateMatcher::Delegate::new
# File lib/delegate_matcher/nil_delegate.rb, line 5 def initialize(expected, to, &block) super original_receiver = receiver self.receiver = nil block.call ensure self.receiver = original_receiver end
Private Instance Methods
receiver=(value)
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/delegate_matcher/nil_delegate.rb, line 17 def receiver=(value) case when a_class_variable? subject.class.class_variable_set(name, value) when an_instance_variable? subject.instance_variable_set(name, value) when a_constant? silence_warnings { subject.class.const_set(name, value) } when a_method? allow(subject).to receive(name) { value } else # an object fail 'cannot verify "allow_nil" expectations when delegating to an object' if value.nil? end end
silence_warnings(&block)
click to toggle source
# File lib/delegate_matcher/nil_delegate.rb, line 32 def silence_warnings(&block) warn_level = $VERBOSE $VERBOSE = nil block.call ensure $VERBOSE = warn_level end