1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
module RSpec
module Mocks
# @private
class ProxyForNil < Proxy
def initialize
@warn_about_expectations = true
super nil
end
attr_accessor :warn_about_expectations
alias warn_about_expectations? warn_about_expectations
def add_message_expectation(location, method_name, opts={}, &block)
warn(method_name) if warn_about_expectations?
super
end
def add_negative_message_expectation(location, method_name, &implementation)
warn(method_name) if warn_about_expectations?
super
end
def add_stub(location, method_name, opts={}, &implementation)
warn(method_name) if warn_about_expectations?
super
end
private
def warn method_name
non_rspec_caller = caller.find { |line| !line.include?('lib/rspec/mocks') }
Kernel.warn("An expectation of :#{method_name} was set on nil. Called from #{non_rspec_caller}. Use allow_message_expectations_on_nil to disable warnings.")
end
end
end
end
|