Browse files

add deprecation module and begin to standardize deprecation messages

  • Loading branch information...
1 parent 7189fd7 commit 530d44eb0ea14bf145cbbcf8063d484422b20065 @dchelimsky committed Apr 1, 2009
View
1 lib/spec.rb
@@ -1,3 +1,4 @@
+require 'spec/deprecation'
require 'spec/ruby'
require 'spec/matchers'
require 'spec/expectations'
View
29 lib/spec/deprecation.rb
@@ -0,0 +1,29 @@
+module Spec
+ class << self
+ def deprecate(method, alternate_method=nil)
+ message = <<-NOTICE
+
+DEPRECATION WARNING: you are using deprecated behaviour that will
+be removed from a future version of RSpec.
+
+#{method} is deprecated.
+NOTICE
+ if alternate_method
+ message << <<-ADDITIONAL
+Please use #{alternate_method} instead.
+ADDITIONAL
+ end
+
+ message << <<-MORE
+
+#{caller(0)[2]}
+MORE
+ warn(message)
+ end
+
+ def warn(message)
+ Kernel.warn(message)
+ end
+ end
+end
+
View
7 lib/spec/example/example_group_methods.rb
@@ -24,11 +24,8 @@ def backtrace
# Deprecated - use +backtrace()+
def example_group_backtrace
- Kernel.warn <<-WARNING
-ExampleGroupMethods#example_group_backtrace is deprecated and will be removed
-from a future version. Please use ExampleGroupMethods#backtrace instead.
-WARNING
- backtrace
+ Spec.deprecate("ExampleGroupMethods#example_group_backtrace", "ExampleGroupMethods#backtrace")
+ defined?(@backtrace) ? @backtrace : nil
end
# Makes the describe/it syntax available from a class. For example:
View
5 lib/spec/example/example_methods.rb
@@ -92,10 +92,7 @@ def backtrace
# Deprecated - use +backtrace()+
def implementation_backtrace
- Kernel.warn <<-WARNING
-ExampleMethods#implementation_backtrace is deprecated and will be removed
-from a future version. Please use ExampleMethods#backtrace instead.
-WARNING
+ Spec.deprecate("ExampleMethods#implementation_backtrace","ExampleMethods#backtrace")
backtrace
end
View
2 lib/spec/mocks/spec_methods.rb
@@ -32,7 +32,7 @@ def mock(name, stubs_and_options={})
# to any message it receives that it hasn't been explicitly instructed
# to respond to.
def stub_everything(name = 'stub')
- Kernel.warn(<<-WARNING)
+ Spec.warn(<<-WARNING)
DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
from a future version of rspec. Please use mock('#{name}').as_null_object
View
14 lib/spec/runner/formatter/base_text_formatter.rb
@@ -46,12 +46,7 @@ def colorize_failure(message, failure)
end
def colourise(message, failure)
- Kernel.warn <<-NOTICE
-DEPRECATED: BaseTextFormatter#colourise is deprecated and will be
-removed from a future version of RSpec.
-
-Please use colorize_failure instead.
-NOTICE
+ Spec::deprecate("BaseTextFormatter#colourise", "colorize_failure")
colorize_failure(message, failure)
end
@@ -132,12 +127,9 @@ def green(text); colour(text, "\e[32m"); end
def red(text); colour(text, "\e[31m"); end
def yellow(text); colour(text, "\e[33m"); end
def blue(text); colour(text, "\e[34m"); end
-
+
def magenta(text)
- Kernel.warn <<-NOTICE
-DEPRECATED: BaseTextFormatter#magenta is deprecated and will be
-removed from a future version of RSpec.
-NOTICE
+ Spec::deprecate("BaseTextFormatter#magenta")
red(text)
end
end
View
4 lib/spec/runner/reporter.rb
@@ -104,7 +104,7 @@ def example_passed(example)
end
EXAMPLE_PENDING_DEPRECATION_WARNING = <<-WARNING
- DEPRECATION NOTICE: RSpec's formatters have changed example_pending
+ DEPRECATION WARNING: RSpec's formatters have changed example_pending
to accept two arguments instead of three. Please see the rdoc
for Spec::Runner::Formatter::BaseFormatter#example_pending
for more information.
@@ -118,7 +118,7 @@ def example_pending(example, ignore, message="Not Yet Implemented")
@pending_count += 1
formatters.each do |formatter|
if formatter_uses_deprecated_example_pending_method?(formatter)
- Kernel.warn EXAMPLE_PENDING_DEPRECATION_WARNING
+ Spec.warn EXAMPLE_PENDING_DEPRECATION_WARNING
formatter.example_pending(example, message, example.location)
else
formatter.example_pending(example, message)
View
4 spec/spec/example/example_group_methods_spec.rb
@@ -612,11 +612,11 @@ def self.to_s
describe "#example_group_backtrace (deprecated)" do
before(:each) do
- Kernel.stub!(:warn)
+ Spec.stub!(:deprecate)
end
it "sends a deprecation warning" do
example_group = Class.new(ExampleGroupDouble) {}
- Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
+ Spec.should_receive(:deprecate)
example_group.example_group_backtrace
end
View
4 spec/spec/runner/formatter/base_text_formatter_spec.rb
@@ -37,7 +37,7 @@ def method_that_class_colourise(message, failure)
context "#colourise" do
it "warns when subclasses call colourise" do
- Kernel.should_receive(:warn).with(/DEPRECATED/)
+ Spec.should_receive(:deprecate)
@formatter.method_that_class_colourise('this message', @failure)
end
@@ -49,7 +49,7 @@ def method_that_class_colourise(message, failure)
context "#magenta" do
it "warns when subclasses call magenta" do
- Kernel.should_receive(:warn).with(/DEPRECATED/)
+ Spec.should_receive(:deprecate).with(/#magenta/)
@formatter.method_that_class_magenta('this message')
end
View
4 spec/spec/runner/reporter_spec.rb
@@ -188,7 +188,7 @@ def description_of(example)
describe "to formatters which have example_pending's arity of 3 (which is now deprecated)" do
before :each do
- Kernel.stub!(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
+ Spec.stub!(:warn)
@deprecated_formatter = Class.new(@formatter.class) do
attr_reader :example_passed_to_method, :message_passed_to_method
@@ -220,7 +220,7 @@ def example_pending(example_passed_to_method, message_passed_to_method, deprecat
end
it "should raise a deprecation warning" do
- Kernel.should_receive(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
+ Spec.should_receive(:warn)
example = ExampleGroup.new(example_proxy)
example_group.notify(reporter)

0 comments on commit 530d44e

Please sign in to comment.