deprecations 2.2.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c5899644bd44226740f7c81c5b404d0bc942bbf256ecc47f540295bebab351a
4
- data.tar.gz: d5bfacd79de9a17bf16d8c6c95c29b0e1cc538bc975b188d73a515a0726aaf92
3
+ metadata.gz: 9973f05a62830c682760b9becfce855fa3e25d2bfdb40a0516846b5e3e27297f
4
+ data.tar.gz: 77b6ca73354da20235e652895d30513dc4f3ab47dd3bd73658eeb250d2cac52c
5
5
  SHA512:
6
- metadata.gz: 0af667f71e7e2c2484114c00301cb44e1007ef7eae467fe3cdf6f00fa5011441078b29732a3f6a83a51a32af6409ba8ae772df1bb2b6bc1744768eed125d24da
7
- data.tar.gz: 0d2f21c5421992fd44110ae87fda1325eb16c946c692308fd3a51c5bbe86db86789905fbd4d71d325b152cbe1c9116ea796c04a08db100a2f6adff5ea1d47d4a
6
+ metadata.gz: 190ddcd1b3f3f750d83579d369f02b12fc03f6fdd4a21a05b5d58a3d830d72b49c696bebbd8e27e431458a0224162a00bc1fa79f59851b608b5f9547b7e111ca
7
+ data.tar.gz: 14e17835fd8c727d3a30db5f22673918373969a4b687c494e67abe6b83e9f8e72ee0c6dcab98b63bca8e08926506e98c076e89a59acd9ae457787b42a01cd91b
data/README.md CHANGED
@@ -14,13 +14,13 @@ gem 'deprecations'
14
14
 
15
15
  and install it by running Bundler:
16
16
 
17
- ```bash
18
- $ bundle
17
+ ```shell
18
+ $ bundle add deprecations
19
19
  ```
20
20
 
21
21
  To install the gem globally use:
22
22
 
23
- ```bash
23
+ ```shell
24
24
  $ gem install deprecations
25
25
  ```
26
26
 
@@ -36,7 +36,6 @@ you can specify which methods and classes are deprecated. To mark a method as de
36
36
 
37
37
  ```ruby
38
38
  class MySample
39
-
40
39
  def clear
41
40
  # something here
42
41
  end
@@ -46,7 +45,6 @@ class MySample
46
45
  end
47
46
 
48
47
  deprecated :clean, :clear, 'next version'
49
-
50
48
  end
51
49
  ```
52
50
 
@@ -79,9 +77,10 @@ There are 3 pre-defined behaviors:
79
77
  Besides this you can implement your own:
80
78
 
81
79
  ```ruby
82
- Deprecations.behavior = proc do |subject, _alternative, _outdated|
83
- SuperLogger.warning "deprecated: #{subject}"
84
- end
80
+ Deprecations.behavior =
81
+ proc do |subject, _alternative, _outdated|
82
+ SuperLogger.warning "deprecated: #{subject}"
83
+ end
85
84
  ```
86
85
 
87
86
  Any object responding to `#call` will be accepted as a valid handler.
@@ -89,9 +88,7 @@ Any object responding to `#call` will be accepted as a valid handler.
89
88
  Whenever you need to temporary change the standard behavior (like e.g. in your specs) you can do this like
90
89
 
91
90
  ```ruby
92
- Deprecations.with_behavior(:silent) do
93
- MyDeprecatedClass.new.do_some_magic
94
- end
91
+ Deprecations.with_behavior(:silent) { MyDeprecatedClass.new.do_some_magic }
95
92
  ```
96
93
 
97
94
  Please have a look at the [specs](https://github.com/mblumtritt/deprecations/blob/master/spec/deprecations_spec.rb) for detailed information and more samples.
@@ -1,23 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Deprecations
2
4
  class << self
3
5
  def behavior
4
6
  BEHAVIOR.key(@behavior) || @behavior
5
7
  end
6
8
 
7
- def behavior=(behavior)
8
- @behavior = as_behavior(behavior)
9
+ def behavior=(value)
10
+ @behavior = as_behavior(value)
9
11
  end
10
12
 
11
13
  def with_behavior(behavior)
12
14
  behavior = as_behavior(behavior)
13
15
  raise(ArgumentError, 'block expected') unless block_given?
14
16
  current_behavior = @behavior
15
- begin
16
- @behavior = behavior
17
- yield
18
- ensure
19
- @behavior = current_behavior
20
- end
17
+ @behavior = behavior
18
+ yield
19
+ ensure
20
+ @behavior = current_behavior if current_behavior
21
21
  end
22
22
 
23
23
  alias set_behavior with_behavior
@@ -30,7 +30,7 @@ module Deprecations
30
30
  raise(
31
31
  ArgumentError,
32
32
  'invalid parameter - behavior has to be ' \
33
- "#{valid_behaviors} or need to respond to `call`"
33
+ "#{valid_behaviors} or need to respond to `#call`"
34
34
  )
35
35
  end
36
36
  end
@@ -41,23 +41,29 @@ module Deprecations
41
41
 
42
42
  module Raise
43
43
  def self.call(subject, alternative, _outdated)
44
- msg = "`#{subject}` is deprecated"
45
- msg << " - use #{alternative} instead" if alternative
46
- ex = Error.new(msg)
47
- ex.set_backtrace(caller(3))
48
- raise(ex)
44
+ raise(
45
+ Error
46
+ .new(
47
+ "`#{subject}` is deprecated#{
48
+ " - use #{alternative} instead" if alternative
49
+ }"
50
+ )
51
+ .tap { |error| error.set_backtrace(caller(3)) }
52
+ )
49
53
  end
50
54
  end
51
55
 
52
56
  module Warn
53
57
  def self.call(subject, alternative, outdated)
54
- msg = "`#{subject}` is deprecated"
55
- msg << (outdated ? " and will be outdated #{outdated}." : '.')
56
- msg << " Please use `#{alternative}` instead." if alternative
57
- ::Kernel.warn(msg, uplevel: 3)
58
+ ::Kernel.warn(
59
+ "`#{subject}` is deprecated#{
60
+ outdated ? " and will be outdated #{outdated}." : '.'
61
+ }#{" Please use `#{alternative}` instead." if alternative}",
62
+ uplevel: 3
63
+ )
58
64
  end
59
65
  end
60
66
 
61
- BEHAVIOR = {silence: proc {}, raise: Raise, warn: Warn}.freeze
67
+ BEHAVIOR = { silence: proc {}, raise: Raise, warn: Warn }.freeze
62
68
  end
63
69
  end
@@ -1,76 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deprecations
4
- class << self
5
- private
6
-
7
- def infect(mod)
8
- mod.extend(ClassMethods)
9
- mod.send(:include, InstanceMethods)
10
- end
11
-
12
- module Helper
13
- private
14
-
15
- def __method(method_name)
16
- instance_method(method_name) rescue nil
17
- end
4
+ private_class_method def self.infect(mod)
5
+ mod.extend(ClassMethods)
6
+ mod.__send__(:include, InstanceMethods)
7
+ end
18
8
 
19
- def __method_deprecated!(method, alternative, outdated)
20
- defining_context = self
21
- undef_method(method.name)
22
- define_method(method.name) do |*a, &b|
23
- decorated = Class === self ? "#{self}." : "#{defining_context}#"
24
- alternative = "#{decorated}#{alternative.name}" if UnboundMethod === alternative
25
- Deprecations.call("#{decorated}#{::Kernel.__method__}", alternative, outdated)
26
- method.bind(self).call(*a, &b)
27
- end
28
- end
9
+ module ClassMethods
10
+ private
29
11
 
30
- def __method_checked(method_name)
31
- __method(method_name) or raise(
32
- NameError, "undefined method `#{method_name}` for class `#{self}`"
12
+ def deprecated(method_name, alternative = nil, outdated = nil)
13
+ alias_name = "__deprecated__singleton_method__#{method_name}__"
14
+ return if private_method_defined?(alias_name)
15
+ alias_method(alias_name, method_name)
16
+ private(alias_name)
17
+ alternative = instance_method(alternative) if alternative.is_a?(Symbol)
18
+ define_method(method_name) do |*args, **kw_args, &b|
19
+ Deprecations.call(
20
+ "#{self}.#{::Kernel.__method__}",
21
+ if alternative.is_a?(UnboundMethod)
22
+ "#{self}.#{alternative.name}"
23
+ else
24
+ alternative
25
+ end,
26
+ outdated
33
27
  )
34
- end
35
-
36
- def __method_alternative(alternative)
37
- Symbol === alternative ? __method_checked(alternative) : alternative
28
+ __send__(alias_name, *args, **kw_args, &b)
38
29
  end
39
30
  end
31
+ end
40
32
 
41
- module ClassMethods
42
- private
43
-
44
- include Helper
33
+ module InstanceMethods
34
+ private
45
35
 
46
- def deprecated(method_name, alternative = nil, outdated = nil)
47
- __method_deprecated!(
48
- __method_checked(method_name),
49
- __method_alternative(alternative),
36
+ def deprecated(method_name, alternative = nil, outdated = nil)
37
+ alias_name = "__deprecated__instance_method__#{method_name}__"
38
+ return if private_method_defined?(alias_name)
39
+ alias_method(alias_name, method_name)
40
+ private(alias_name)
41
+ alternative = instance_method(alternative) if alternative.is_a?(Symbol)
42
+ define_method(method_name) do |*args, **kw_args, &b|
43
+ pref =
44
+ if defined?(self.class.name)
45
+ self.class.name
46
+ else
47
+ Kernel.instance_method(:class).bind(self).call
48
+ end
49
+ Deprecations.call(
50
+ "#{pref}##{::Kernel.__method__}",
51
+ if alternative.is_a?(UnboundMethod)
52
+ "#{pref}##{alternative.name}"
53
+ else
54
+ alternative
55
+ end,
50
56
  outdated
51
57
  )
58
+ __send__(alias_name, *args, **kw_args, &b)
52
59
  end
60
+ rescue NameError
61
+ raise if private_method_defined?(alias_name)
62
+ singleton_class.__send__(:deprecated, method_name, alternative, outdated)
53
63
  end
54
64
 
55
- module InstanceMethods
56
- private
57
-
58
- include Helper
59
-
60
- def deprecated(method_name, alternative = nil, outdated = nil)
61
- m = __method(method_name) or return singleton_class.send(
62
- :deprecated, method_name, alternative, outdated
63
- )
64
- __method_deprecated!(m, __method_alternative(alternative), outdated)
65
- end
66
-
67
- def deprecated!(alternative = nil, outdated = nil)
68
- m = method(:new)
69
- define_singleton_method(:new) do |*a, &b|
70
- Deprecations.call(self, alternative, outdated)
71
- m.call(*a, &b)
72
- end
65
+ def deprecated!(alternative = nil, outdated = nil)
66
+ org = method(:new)
67
+ define_singleton_method(:new) do |*args, **kw_args, &b|
68
+ Deprecations.call(name, alternative, outdated)
69
+ org.call(*args, **kw_args, &b)
73
70
  end
71
+ rescue NameError
72
+ nil
74
73
  end
75
74
  end
76
75
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deprecations
4
- VERSION = '2.2.0'
4
+ VERSION = '2.5.0'
5
5
  end
data/lib/deprecations.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Deprecations
2
- require_relative 'deprecations/version'
3
- require_relative 'deprecations/extension'
4
4
  require_relative 'deprecations/behavior'
5
+ require_relative 'deprecations/extension'
6
+ require_relative 'deprecations/version'
5
7
 
6
8
  Error = Class.new(ScriptError)
7
9
 
metadata CHANGED
@@ -1,84 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-19 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '1.10'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 10.1.1
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 10.1.1
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 3.0.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 3.0.0
11
+ date: 2023-12-22 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: |
56
14
  This gem provides transparent declaration of deprecated methods and classes.
57
15
  It's easy, small, has no dependencies and no overhead.
58
- email: mike.blumtritt@invision.de
16
+ email:
59
17
  executables: []
60
18
  extensions: []
61
19
  extra_rdoc_files:
62
20
  - README.md
63
21
  files:
64
- - ".gitignore"
65
22
  - README.md
66
- - deprecations.gemspec
67
- - gems.rb
68
23
  - lib/deprecations.rb
69
24
  - lib/deprecations/behavior.rb
70
25
  - lib/deprecations/extension.rb
71
26
  - lib/deprecations/version.rb
72
- - rakefile.rb
73
- - spec/deprecations/behavior_spec.rb
74
- - spec/deprecations/version_spec.rb
75
- - spec/deprecations_spec.rb
76
- - spec/spec_helper.rb
77
27
  homepage: https://github.com/mblumtritt/deprecations
78
28
  licenses: []
79
29
  metadata:
80
- issue_tracker: https://github.com/mblumtritt/deprecations/issues
81
- post_install_message:
30
+ source_code_uri: https://github.com/mblumtritt/deprecations
31
+ bug_tracker_uri: https://github.com/mblumtritt/deprecations/issues
32
+ rubygems_mfa_required: 'true'
33
+ post_install_message:
82
34
  rdoc_options: []
83
35
  require_paths:
84
36
  - lib
@@ -86,20 +38,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
38
  requirements:
87
39
  - - ">="
88
40
  - !ruby/object:Gem::Version
89
- version: 2.0.0
41
+ version: 2.7.0
90
42
  required_rubygems_version: !ruby/object:Gem::Requirement
91
43
  requirements:
92
44
  - - ">="
93
45
  - !ruby/object:Gem::Version
94
- version: 1.10.0
46
+ version: '0'
95
47
  requirements: []
96
- rubyforge_project: deprecations
97
- rubygems_version: 2.7.7
98
- signing_key:
48
+ rubygems_version: 3.5.1
49
+ signing_key:
99
50
  specification_version: 4
100
51
  summary: Deprecation support for your project.
101
- test_files:
102
- - spec/deprecations/behavior_spec.rb
103
- - spec/deprecations/version_spec.rb
104
- - spec/deprecations_spec.rb
105
- - spec/spec_helper.rb
52
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- tmp/
2
- local/
3
- diea/
4
- pkg/
5
- gems.locked
data/deprecations.gemspec DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './lib/deprecations/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = spec.rubyforge_project = 'deprecations'
7
- spec.version = Deprecations::VERSION
8
- spec.summary = 'Deprecation support for your project.'
9
- spec.description = <<~DESCRIPTION
10
- This gem provides transparent declaration of deprecated methods and classes.
11
- It's easy, small, has no dependencies and no overhead.
12
- DESCRIPTION
13
- spec.author = 'Mike Blumtritt'
14
- spec.email = 'mike.blumtritt@invision.de'
15
- spec.homepage = 'https://github.com/mblumtritt/deprecations'
16
- spec.metadata = {'issue_tracker' => 'https://github.com/mblumtritt/deprecations/issues'}
17
-
18
- spec.add_development_dependency 'bundler', '>= 1.10'
19
- spec.add_development_dependency 'rake', '>= 10.1.1'
20
- spec.add_development_dependency 'rspec', '>= 3.0.0'
21
-
22
- spec.platform = Gem::Platform::RUBY
23
- spec.required_ruby_version = '>= 2.0.0'
24
- spec.required_rubygems_version = Gem::Requirement.new('>= 1.10.0')
25
-
26
- spec.require_paths = %w[lib]
27
-
28
- all_files = %x(git ls-files -z).split(0.chr)
29
- spec.test_files = all_files.grep(%r{^(spec|test)/})
30
- spec.files = all_files - spec.test_files
31
-
32
- spec.extra_rdoc_files = %w[README.md]
33
- end
data/gems.rb DELETED
@@ -1 +0,0 @@
1
- source('https://rubygems.org'){ gemspec }
data/rakefile.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:test) do |t|
5
- t.pattern = ['spec/*_spec.rb', 'spec/**/*/*_spec.rb']
6
- t.rspec_opts = '-w'
7
- t.verbose = Rake.application.options.trace
8
- end
9
-
10
- task :default do
11
- exec "#{$0} --task"
12
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Deprecations do
4
- context 'behavior' do
5
-
6
- it 'is possible to configure the behavior with a pre-defined value' do
7
- %i(silence raise warn).each do |behavior|
8
- Deprecations.behavior = behavior
9
- expect(Deprecations.behavior).to be(behavior)
10
- end
11
- end
12
-
13
- it 'is possible to configure a custom behavior' do
14
- custom = proc do |*args|
15
- FantasticLogger.log(*args)
16
- end
17
- Deprecations.behavior = custom
18
- expect(Deprecations.behavior).to be(custom)
19
- end
20
-
21
- context 'standard behavior :silence' do
22
- before do
23
- Deprecations.behavior = :silence
24
- end
25
-
26
- it 'does simply nothing' do
27
- expect(subject.call(*%w(should be silent))).to be(subject)
28
- end
29
- end
30
-
31
- context 'standard behavior :warn' do
32
- before do
33
- Deprecations.behavior = :warn
34
- end
35
- after do
36
- Deprecations.call('Bad#method', 'Bad#alternative', 'after next version')
37
- end
38
-
39
- it 'warns about the deprecation' do
40
- expect(Kernel).to receive(:warn).once.with(/.*/, uplevel: 3)
41
- end
42
-
43
- it 'points to the deprecated method' do
44
- expect(Kernel).to receive(:warn).once.with(/Bad#method.*deprecated/, uplevel: 3)
45
- end
46
-
47
- it 'suggests the alternative method' do
48
- expect(Kernel).to receive(:warn).once.with(/Bad#alternative.*instead/, uplevel: 3)
49
- end
50
-
51
- it 'contains information about when it will not longer supported' do
52
- expect(Kernel).to receive(:warn).once.with(/outdated after next version/, uplevel: 3)
53
- end
54
- end
55
-
56
- context 'standard behavior :raise' do
57
- before do
58
- Deprecations.behavior = :raise
59
- end
60
- subject{ Deprecations.call('Bad#method', 'Bad#alternative', 'after next version') }
61
-
62
- it 'raises a Deprecations::Error' do
63
- expect{ subject }.to raise_error(Deprecations::Error)
64
- end
65
-
66
- it 'points to the deprecated method' do
67
- expect{ subject }.to raise_error(Deprecations::Error, /Bad#method.*deprecated/)
68
- end
69
-
70
- it 'suggests the alternative method' do
71
- expect{ subject }.to raise_error(Deprecations::Error, /Bad#alternative.*instead/)
72
- end
73
- end
74
-
75
- context 'change behavior temporary' do
76
- let(:sample_class) do
77
- Class.new(BasicObject) do
78
- deprecated!
79
- end
80
- end
81
-
82
- before do
83
- Deprecations.behavior = :raise
84
- end
85
-
86
- after do
87
- Deprecations.with_behavior(:warn) do
88
- sample_class.new.__id__
89
- end
90
- end
91
-
92
- it 'is possible to temporary use a different behavior' do
93
- expect(Kernel).to receive(:warn).once
94
- end
95
- end
96
- end
97
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Deprecations::VERSION' do
4
- it 'has format <major>.<minor>.<build>' do
5
- expect(Deprecations::VERSION).to match(/^\d{1,2}\.\d{1,2}\.\d{1,3}/)
6
- end
7
- end
@@ -1,235 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Deprecations do
4
- context 'policy' do
5
- before do
6
- Deprecations.behavior = :silence
7
- end
8
-
9
- context 'parameter forwarding' do
10
-
11
- context 'when an instance method is marked as deprecated' do
12
- subject do
13
- Class.new(BasicObject) do
14
- def foo(*args)
15
- {foo: args}
16
- end
17
- deprecated :foo
18
- end
19
- end
20
-
21
- it 'forwards all parameters and returns the original method`s result' do
22
- result = subject.new.foo(:arg1, :arg2, 42)
23
- expect(result).to eq(foo: [:arg1, :arg2, 42])
24
- end
25
- end
26
-
27
- context 'when a class method is marked as deprecated' do
28
- subject do
29
- Class.new(BasicObject) do
30
- def self.foo(*args)
31
- {foo: args}
32
- end
33
- deprecated :foo
34
- end
35
- end
36
-
37
- it 'forwards all parameters and returns the original method`s result' do
38
- result = subject.foo(:arg1, :arg2, 42)
39
- expect(result).to eq(foo: [:arg1, :arg2, 42])
40
- end
41
- end
42
-
43
- context 'when a class is marked as deprecated' do
44
- subject do
45
- Class.new(BasicObject) do
46
- attr_reader :parameters
47
- def initialize(*parameters)
48
- @parameters = parameters
49
- end
50
- deprecated!
51
- end
52
- end
53
-
54
- it 'forwards all parameters to the initializer and returns the original method`s result' do
55
- expect(subject.new(:arg1, :arg2, 42).parameters).to eq([:arg1, :arg2, 42])
56
- end
57
- end
58
-
59
- end
60
-
61
- context 'block forwarding' do
62
-
63
- context 'when an instance method is marked as deprecated' do
64
- subject do
65
- Class.new(BasicObject) do
66
- def foo(arg)
67
- yield(arg)
68
- end
69
- deprecated :foo
70
- end
71
- end
72
-
73
- it 'forwards a given Proc to the original method' do
74
- result = subject.new.foo(41) do |arg|
75
- {my_blocks_result: arg + 1}
76
- end
77
- expect(result).to eq(my_blocks_result: 42)
78
- end
79
- end
80
-
81
- context 'when a class method is marked as deprecated' do
82
- subject do
83
- Class.new(BasicObject) do
84
- def self.foo(arg)
85
- yield(arg)
86
- end
87
- deprecated :foo
88
- end
89
- end
90
-
91
- it 'forwards a given Proc to the original method' do
92
- result = subject.foo(665) do |arg|
93
- {my_blocks_result: arg + 1}
94
- end
95
- expect(result).to eq(my_blocks_result: 666)
96
- end
97
- end
98
-
99
- context 'when a class is marked as deprecated' do
100
- subject do
101
- Class.new(BasicObject) do
102
- attr_reader :value
103
- def initialize(arg)
104
- @value = yield(arg)
105
- end
106
- deprecated!
107
- end
108
- end
109
-
110
- it 'forwards a given Proc to the initializer' do
111
- instance = subject.new(41) do |arg|
112
- {my_blocks_result: arg + 1}
113
- end
114
- expect(instance.value).to eq(my_blocks_result: 42)
115
- end
116
- end
117
-
118
- end
119
-
120
- end
121
-
122
- context 'handling' do
123
-
124
- context 'when a method is marked as deprecated' do
125
-
126
- context 'when an alternative method and a comment are present ' do
127
- subject do
128
- Class.new(BasicObject) do
129
- def foo
130
- end
131
- def bar
132
- end
133
- deprecated :foo, :bar, 'next version'
134
- end
135
- end
136
-
137
- after do
138
- subject.new.foo
139
- end
140
-
141
- it 'calls the handler with correct subject' do
142
- expect(Deprecations).to receive(:call)
143
- .once
144
- .with("#{subject}#foo", anything, anything)
145
- end
146
- it 'calls the handler with correct alternative method' do
147
- expect(Deprecations).to receive(:call)
148
- .once
149
- .with(anything, "#{subject}#bar", anything)
150
- end
151
- it 'calls the handler with a comment' do
152
- expect(Deprecations).to receive(:call)
153
- .once
154
- .with(anything, anything, 'next version')
155
- end
156
- end
157
-
158
- context 'when no alternative method and no comment are present' do
159
- subject do
160
- Class.new(BasicObject) do
161
- def bar
162
- end
163
- deprecated :bar
164
- end
165
- end
166
-
167
- after do
168
- subject.new.bar
169
- end
170
-
171
- it 'calls handler without an alternative method' do
172
- expect(Deprecations).to receive(:call).once.with(anything, nil, anything)
173
- end
174
- it 'calls handler without a comment' do
175
- expect(Deprecations).to receive(:call).once.with(anything, anything, nil)
176
- end
177
- end
178
-
179
- end
180
-
181
- context 'when a class is anonymous defined' do
182
- module Samples
183
- AnonymousDefined = Class.new(::BasicObject) do
184
- def clean; end
185
- def clear; end
186
- deprecated :clean, :clear
187
-
188
- def self.create; end
189
- def self.make; end
190
- deprecated :create, :make
191
- end
192
- end
193
-
194
- it 'uses correct decorated instance method names' do
195
- expect(Deprecations).to receive(:call).once.with(
196
- 'Samples::AnonymousDefined#clean',
197
- 'Samples::AnonymousDefined#clear',
198
- nil
199
- )
200
- Samples::AnonymousDefined.new.clean
201
- end
202
-
203
- it 'uses correct decorated singleton method names' do
204
- expect(Deprecations).to receive(:call).once.with(
205
- 'Samples::AnonymousDefined.create',
206
- 'Samples::AnonymousDefined.make',
207
- nil
208
- )
209
- Samples::AnonymousDefined.create
210
- end
211
- end
212
-
213
- context 'when a sub-class is used' do
214
- module Samples
215
- class Parent < ::BasicObject
216
- def clean; end
217
- def clear; end
218
- deprecated :clean, :clear
219
- end
220
-
221
- class Child < Parent; end
222
- end
223
-
224
- it 'uses correct decorated method names' do
225
- expect(Deprecations).to receive(:call).once.with(
226
- 'Samples::Parent#clean',
227
- 'Samples::Parent#clear',
228
- nil
229
- )
230
- Samples::Child.new.clean
231
- end
232
- end
233
-
234
- end
235
- end
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- RSpec.configure do |config|
2
- config.raise_errors_for_deprecations!
3
- config.disable_monkey_patching!
4
- config.expose_dsl_globally = false
5
- config.expect_with(:rspec){ |c| c.syntax = :expect }
6
- config.mock_with(:rspec){ |c| c.syntax = :expect }
7
- end
8
- require 'deprecations'