Sha256: 26eb2a73a228ca9f21dab288b5eb06ec13f7c1ca7a8e7fb63e4ec3af1ca742c4

Contents?: true

Size: 1.03 KB

Versions: 29

Compression:

Stored size: 1.03 KB

Contents

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

Version data entries

29 entries across 29 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/lib/rspec/mocks/proxy_for_nil.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
rspec-mocks-2.14.6 lib/rspec/mocks/proxy_for_nil.rb
rspec-mocks-2.14.5 lib/rspec/mocks/proxy_for_nil.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
dxruby_rp5-0.0.3 spec/vendor/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
tuktuk-rails-0.0.9 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
tuktuk-rails-0.0.8 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
tuktuk-rails-0.0.7 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb
dxruby_rp5-0.0.2 spec/vendor/rspec-mocks-2.14.4/lib/rspec/mocks/proxy_for_nil.rb