Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

unify warning files and match core

  • Loading branch information...
commit 659b039405bbb4df9532e60c3503ae066757bb76 1 parent 1712a90
@JonRowe JonRowe authored
View
18 lib/rspec/mocks/deprecation.rb
@@ -1,18 +0,0 @@
-module RSpec
- module Mocks
- module Deprecation
- # @private
- #
- # Used internally to print deprecation warnings
- def deprecate(deprecated, options={})
- message = "DEPRECATION: #{deprecated} is deprecated."
- message << " Use #{options[:replacement]} instead." if options[:replacement]
- message << " Called from #{CallerFilter.first_non_rspec_line}."
- warn message
- end
- end
- end
-
- extend(Mocks::Deprecation) unless respond_to?(:deprecate)
-end
-
View
3  lib/rspec/mocks/framework.rb
@@ -3,8 +3,7 @@
# object in the system.
require 'rspec/mocks/caller_filter' unless defined?(::RSpec::CallerFilter)
-require 'rspec/mocks/deprecation'
-require 'rspec/mocks/warning'
+require 'rspec/mocks/warnings'
require 'rspec/mocks/instance_method_stasher'
require 'rspec/mocks/method_double'
require 'rspec/mocks/argument_matchers'
View
22 lib/rspec/mocks/warning.rb
@@ -1,22 +0,0 @@
-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
-
View
37 lib/rspec/mocks/warnings.rb
@@ -0,0 +1,37 @@
+module RSpec
+
+ # We don't redefine the deprecation helpers
+ # when they already exist (defined by rspec-core etc)
+ unless respond_to?(:deprecate)
+
+ # @private
+ #
+ # Used internally to print deprecation warnings
+ def self.deprecate(deprecated, options = {})
+ warn_with "DEPRECATION: #{deprecated} is deprecated.", options
+ end
+
+ end
+
+ # We don't redefine the warnings helpers
+ # when they already exist (defined by rspec-core etc)
+ unless respond_to?(:warning) && respond_to?(:warn_with)
+
+ # @private
+ #
+ # Used internally to print deprecation warnings
+ def self.warning(text, options={})
+ warn_with "WARNING: #{text}.", options
+ end
+
+ # @private
+ #
+ # Used internally to longer warnings
+ def self.warn_with(message, options = {})
+ message << " Use #{options[:replacement]} instead." if options[:replacement]
+ message << " Called from #{CallerFilter.first_non_rspec_line}."
+ ::Kernel.warn message
+ end
+
+ end
+end
View
10 spec/rspec/mocks/and_call_original_spec.rb
@@ -22,7 +22,7 @@ def self.new_instance
let(:instance) { klass.new }
it 'passes the received message through to the original method' do
- allow(instance).to receive(:meth_1).and_call_original
+ expect(instance).to receive(:meth_1).and_call_original
expect(instance.meth_1).to eq(:original)
end
@@ -33,14 +33,14 @@ def self.new_instance
end
it 'passes args and blocks through to the original method' do
- allow(instance).to receive(:meth_2).and_call_original
+ expect(instance).to receive(:meth_2).and_call_original
value = instance.meth_2(:submitted_arg) { |a, b| [a, b] }
expect(value).to eq([:submitted_arg, :additional_yielded_arg])
end
it 'errors when you pass through the wrong number of args' do
- allow(instance).to receive(:meth_1).and_call_original
- allow(instance).to receive(:meth_2).and_call_original
+ expect(instance).to receive(:meth_1).and_call_original
+ expect(instance).to receive(:meth_2).twice.and_call_original
expect { instance.meth_1 :a }.to raise_error ArgumentError
expect { instance.meth_2 {} }.to raise_error ArgumentError
expect { instance.meth_2(:a, :b) {} }.to raise_error ArgumentError
@@ -48,7 +48,7 @@ def self.new_instance
it 'warns when you override an existing implementation' do
expect(RSpec).to receive(:warning).with /overriding a previous implementation/
- allow(instance).to receive(:meth_1) { true }.and_call_original
+ expect(instance).to receive(:meth_1) { true }.and_call_original
instance.meth_1
end
Please sign in to comment.
Something went wrong with that request. Please try again.