Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

deprecation and warning reworking

  • Loading branch information...
commit f8662adf7df615f005f5c88b84ebd651257dfc99 1 parent 07f96d4
@JonRowe JonRowe authored
Showing with 23 additions and 0 deletions.
  1. +1 −0  lib/rspec/mocks/framework.rb
  2. +22 −0 lib/rspec/mocks/warning.rb
View
1  lib/rspec/mocks/framework.rb
@@ -4,6 +4,7 @@
require 'rspec/mocks/caller_filter' unless defined?(::RSpec::CallerFilter)
require 'rspec/mocks/deprecation'
+require 'rspec/mocks/warning'
require 'rspec/mocks/instance_method_stasher'
require 'rspec/mocks/method_double'
require 'rspec/mocks/argument_matchers'
View
22 lib/rspec/mocks/warning.rb
@@ -0,0 +1,22 @@
+module RSpec
+ module Mocks
+ module Warning
+ # @private
+ #
+ # Used internally to print deprecation warnings
+ def warning(text, options={})
+ warn_with "WARNING: #{text}.", options
+ end
+
+ def warn_with(message, options = {})
+ line = caller.find { |line| line !~ %r{/lib/rspec/(core|mocks|expectations|matchers|rails)/} }
+ message << " Use #{options[:replacement]} instead." if options[:replacement]
+ message << " Called from #{line}."
+ ::Kernel.warn message
+ end
+ end
+ end
+
+ extend(Mocks::Warning) unless respond_to?(:warning) && respond_to?(:warn_with)
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.