class RSpec::Mocks::ProxyForNil

@private

def add_message_expectation(method_name, opts={}, &block)

def add_message_expectation(method_name, opts={}, &block)
  warn_or_raise!(method_name)
  super
end

def add_stub(method_name, opts={}, &implementation)

def add_stub(method_name, opts={}, &implementation)
  warn_or_raise!(method_name)
  super
end

def initialize(order_group)

def initialize(order_group)
  set_expectation_behavior
  super(nil, order_group)
end

def raise_error(method_name)

def raise_error(method_name)
  @error_generator.raise_expectation_on_nil_error(method_name)
end

def set_expectation_behavior

def set_expectation_behavior
  case RSpec::Mocks.configuration.allow_message_expectations_on_nil
  when false
    @warn_about_expectations = false
    @disallow_expectations = true
  when true
    @warn_about_expectations = false
    @disallow_expectations = false
  else
    @warn_about_expectations = true
    @disallow_expectations = false
  end
end

def warn(method_name)

def warn(method_name)
  warning_msg = @error_generator.expectation_on_nil_message(method_name)
  RSpec.warning(warning_msg)
end

def warn_or_raise!(method_name)

def warn_or_raise!(method_name)
  # This method intentionally swallows the message when
  # neither disallow_expectations nor warn_about_expectations
  # are set to true.
  if disallow_expectations
    raise_error(method_name)
  elsif warn_about_expectations
    warn(method_name)
  end
end