aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/lib/spec/deprecation.rb
blob: ebab78942ac33d53daf549af15cdf4e2ff5722ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.

#{caller(0)[2]}

* #{method} is deprecated.
NOTICE
      if alternate_method
        message << <<-ADDITIONAL
* please use #{alternate_method} instead.
ADDITIONAL
      end

      message << "*****************************************************************"
      warn(message)
    end

    def warn(message)
      Kernel.warn(message)
    end

  end

  class HashWithDeprecationNotice < Hash
    def initialize(method, alternate_method=nil, &block)
      @method, @alternate_method = method, alternate_method
    end
    def []=(k,v)
      Spec.deprecate(@method, @alternate_method)
      super
    end
  end
end