deprecate 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 28e14e1af502d891c520d0cd16d812a324fedc4e
4
- data.tar.gz: 46f96120e8c8704c30f38680a44733193010fa85
2
+ SHA256:
3
+ metadata.gz: 894e5fdc4e539804fd5e5701bfa28b79fc331142c845d904a51a5c3bdf1b617d
4
+ data.tar.gz: 05265c29e32f28474649d170ec6f7f60e5065976b6d327f5534f0368820fed1e
5
5
  SHA512:
6
- metadata.gz: c7d9fdbdca96f918867b46c65eedd3e2722166ec9431c7433bec2b6c741578f26dd9bb8a9313cb23aa7bc7ade5d83111af3eda6c5a44417abf0bfb4aad7bfe65
7
- data.tar.gz: 6870972e92cf07139f59e4d5f97b170f90ba32acc96ff7bc7139a3bda61ce32eeabbd229436a1468536501f55de2ba66c62610d75f54b1bcac8dc3914aa09c84
6
+ metadata.gz: 9234f5c056adf3299bf9b9ba0bd45e61c9f5ff3b902e8620c3f4a90f0ad81187971abeff790f729a14016932130c815f67466d06877ec9ece518fe72193a04b7
7
+ data.tar.gz: 33b9bf8fe007d0775e501a160127a86f93f242ce9290b6d8753d5ed12e81d3306901d5831c7dc05d96b238bc5af71a476b0924e2a2a2b06127c9efd1c1f1b583
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, master ]
6
+ pull_request:
7
+ branches: [ main, master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true
25
+
26
+ - name: Run tests
27
+ run: |
28
+ bundle exec rspec
29
+
30
+ - name: Run manual verification
31
+ run: |
32
+ bundle exec ruby -I lib test_manual.rb
33
+
34
+ quality:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ with:
39
+ fetch-depth: 0
40
+
41
+ - name: Set up Ruby
42
+ uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: '3.3'
45
+ bundler-cache: true
46
+
47
+ - name: Install Qlty
48
+ run: |
49
+ curl -s https://download.qlty.sh/qlty/install.sh | sh
50
+ echo "$HOME/.qlty/bin" >> $GITHUB_PATH
51
+
52
+ - name: Run Qlty
53
+ run: qlty check --reporter github-actions
54
+
55
+ gem:
56
+ runs-on: ubuntu-latest
57
+ needs: [test, quality]
58
+ steps:
59
+ - uses: actions/checkout@v4
60
+
61
+ - name: Set up Ruby
62
+ uses: ruby/setup-ruby@v1
63
+ with:
64
+ ruby-version: '3.3'
65
+ bundler-cache: true
66
+
67
+ - name: Build gem
68
+ run: gem build deprecate.gemspec
69
+
70
+ - name: Install gem locally
71
+ run: gem install ./deprecate-*.gem
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
data/.qlty.toml ADDED
@@ -0,0 +1,50 @@
1
+ [qlty]
2
+ version = "0.1"
3
+
4
+ # Ruby-specific tools
5
+ [[tools]]
6
+ name = "rubocop"
7
+ enabled = true
8
+
9
+ [[tools]]
10
+ name = "reek"
11
+ enabled = true
12
+
13
+ [[tools]]
14
+ name = "flog"
15
+ enabled = true
16
+
17
+ [[tools]]
18
+ name = "flay"
19
+ enabled = true
20
+
21
+ # Security scanning
22
+ [[tools]]
23
+ name = "brakeman"
24
+ enabled = false # Not needed for library gems
25
+
26
+ # General tools
27
+ [[tools]]
28
+ name = "git-diff-check"
29
+ enabled = true
30
+
31
+ [[tools]]
32
+ name = "markdownlint"
33
+ enabled = true
34
+
35
+ # Configure specific tools
36
+ [tools.rubocop]
37
+ config_file = ".rubocop.yml"
38
+
39
+ [tools.reek]
40
+ config_file = ".reek.yml"
41
+
42
+ # Exclude certain paths
43
+ [[exclude]]
44
+ path = "test_manual.rb" # Temporary test file
45
+
46
+ [[exclude]]
47
+ path = "*.gemspec" # Generated files can have long lines
48
+
49
+ [[exclude]]
50
+ path = "Gemfile.lock"
data/.reek.yml ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ detectors:
3
+ # Don't complain about instance variable usage in module
4
+ InstanceVariableAssumption:
5
+ enabled: false
6
+
7
+ # Allow long parameter lists for method wrapping
8
+ LongParameterList:
9
+ max_params: 4
10
+
11
+ # Allow utility modules to be a bit more complex
12
+ TooManyStatements:
13
+ max_statements: 15
14
+
15
+ # Allow some complexity for method interception
16
+ NestedIterators:
17
+ max_allowed_nesting: 2
18
+
19
+ # Don't complain about simple feature envy for configuration access
20
+ FeatureEnvy:
21
+ enabled: false
22
+
23
+ exclude_paths:
24
+ - test_manual.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ Exclude:
5
+ - 'test_manual.rb'
6
+ - 'vendor/**/*'
7
+
8
+ # Allow longer lines for documentation
9
+ Layout/LineLength:
10
+ Max: 100
11
+ AllowedPatterns:
12
+ - '\A\s*#' # Allow long comment lines
13
+
14
+ # Allow class variables for module-level config
15
+ Style/ClassVars:
16
+ Exclude:
17
+ - 'lib/deprecate.rb'
18
+
19
+ # Allow module variables (@config, @warned_methods)
20
+ Style/ModuleFunction:
21
+ Enabled: false
22
+
23
+ # Don't require class documentation for simple classes
24
+ Style/Documentation:
25
+ Exclude:
26
+ - 'test/**/*'
27
+ - 'lib/deprecate/version.rb'
28
+
29
+ # Allow multiple assignments for configuration hash
30
+ Style/HashSyntax:
31
+ EnforcedStyle: ruby19_no_mixed_keys
32
+
33
+ # Don't require frozen string literals for a simple gem
34
+ Style/FrozenStringLiteralComment:
35
+ Enabled: false
36
+
37
+ # Allow method definitions after private
38
+ Layout/EmptyLinesAroundMethodBody:
39
+ Enabled: false
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Deprecate
2
2
 
3
+ [![CI](https://github.com/twilightcoders/deprecate/actions/workflows/ci.yml/badge.svg)](https://github.com/twilightcoders/deprecate/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/deprecate.svg)](https://badge.fury.io/rb/deprecate)
5
+ [![Code Quality](https://img.shields.io/badge/code%20quality-qlty-blue)](https://qlty.sh)
6
+
3
7
  Easily maintain your codebase by exposing an easy and concise way to mark methods as deprecated.
4
8
 
5
9
  ## Installation
@@ -20,7 +24,98 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
23
- Coming soon
27
+ ### Basic Usage
28
+
29
+ Simply call `deprecate` with the method name you want to deprecate:
30
+
31
+ ```ruby
32
+ class MyClass
33
+ def old_method
34
+ "This method still works but is deprecated"
35
+ end
36
+
37
+ def new_method
38
+ "This is the new way"
39
+ end
40
+
41
+ # Mark old_method as deprecated and suggest new_method
42
+ deprecate :old_method, :new_method
43
+ end
44
+
45
+ obj = MyClass.new
46
+ obj.old_method # Works but prints deprecation warning
47
+ # => DEPRECATION WARNING: old_method is deprecated (use new_method instead). Called from example.rb:15
48
+ ```
49
+
50
+ ### Without Replacement Suggestion
51
+
52
+ ```ruby
53
+ class MyClass
54
+ def legacy_method
55
+ "Going away soon"
56
+ end
57
+
58
+ # Mark as deprecated without suggesting replacement
59
+ deprecate :legacy_method
60
+ end
61
+
62
+ obj = MyClass.new
63
+ obj.legacy_method # Prints: DEPRECATION WARNING: legacy_method is deprecated. Called from example.rb:10
64
+ ```
65
+
66
+ ### Configuration
67
+
68
+ Configure deprecation behavior globally:
69
+
70
+ ```ruby
71
+ Deprecate.configure do |config|
72
+ config[:output_stream] = File.open('deprecations.log', 'a') # Log to file instead of stderr
73
+ config[:message_format] = "WARNING: %{method} is deprecated%{replacement}" # Custom message format
74
+ config[:show_caller] = false # Don't show caller location
75
+ config[:warn_once] = false # Warn every time, not just once per method
76
+ end
77
+ ```
78
+
79
+ ### Configuration Options
80
+
81
+ - **`:output_stream`** - Where to send warnings (default: `$stderr`)
82
+ - **`:message_format`** - Message template with `%{method}`, `%{replacement}`, `%{caller}` placeholders
83
+ - **`:show_caller`** - Include caller location in warnings (default: `true`)
84
+ - **`:warn_once`** - Only warn once per deprecated method (default: `true`)
85
+
86
+ ### Resetting Warnings
87
+
88
+ Clear the "warned once" tracking to see warnings again:
89
+
90
+ ```ruby
91
+ Deprecate.reset_warnings!
92
+ ```
93
+
94
+ ### Method Visibility
95
+
96
+ The gem preserves the original method's visibility (public, protected, private):
97
+
98
+ ```ruby
99
+ class MyClass
100
+ private
101
+
102
+ def secret_method
103
+ "private stuff"
104
+ end
105
+
106
+ deprecate :secret_method
107
+
108
+ public
109
+
110
+ def call_secret
111
+ secret_method # This works and shows deprecation warning
112
+ end
113
+ end
114
+
115
+ obj = MyClass.new
116
+ obj.call_secret # Works
117
+ obj.secret_method # Still raises NoMethodError (method remains private)
118
+ ```
24
119
 
25
120
  ## Contributing
26
121
 
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ desc "Run manual verification"
7
+ task :manual do
8
+ sh "ruby -I lib test_manual.rb"
9
+ end
10
+
11
+ task :default => :spec
2
12
 
data/deprecate.gemspec CHANGED
@@ -4,20 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'deprecate/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "deprecate"
7
+ spec.name = 'deprecate'
8
8
  spec.version = Deprecate::VERSION
9
- spec.authors = ["Dale Stevens"]
10
- spec.email = ["dale@twilightcoder.net"]
11
- spec.summary = %q{Easily maintain your codebase by exposing an easy and concise way to mark methods as deprecated.}
12
- # spec.description = %q{Write a longer description. Optional.}
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['Dale Stevens']
10
+ spec.email = ['dale@twilightcoder.net']
11
+ spec.summary = 'Easily maintain your codebase by exposing an easy and concise way to mark methods as deprecated.'
12
+ spec.homepage = 'https://github.com/twilightcoders/deprecate'
13
+ spec.license = 'MIT'
14
+
15
+ spec.required_ruby_version = '>= 2.7.0'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency 'bundler', '~> 2.0'
23
+ spec.add_development_dependency 'rake', '~> 13.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
23
25
  end
@@ -1,3 +1,3 @@
1
1
  module Deprecate
2
- VERSION = "0.0.0"
2
+ VERSION = '0.0.1'
3
3
  end
data/lib/deprecate.rb CHANGED
@@ -1,5 +1,83 @@
1
- require "deprecate/version"
1
+ require 'deprecate/version'
2
+
3
+ class DeprecationError < StandardError; end
2
4
 
3
5
  module Deprecate
4
- # Your code goes here...
6
+ @config = {
7
+ output_stream: $stderr,
8
+ message_format: "DEPRECATION WARNING: %{method} is deprecated%{replacement}. Called from %{caller}",
9
+ show_caller: true,
10
+ warn_once: true
11
+ }
12
+
13
+ @warned_methods = {}
14
+
15
+ class << self
16
+ attr_reader :config, :warned_methods
17
+
18
+ def configure
19
+ yield @config if block_given?
20
+ @config
21
+ end
22
+
23
+ def reset_warnings!
24
+ @warned_methods.clear
25
+ end
26
+ end
27
+
28
+ module Deprecatable
29
+ def __deprecated_run_action__(method_name, replacement = nil)
30
+ method_key = "#{self.class.name}##{method_name}"
31
+
32
+ return if Deprecate.config[:warn_once] && Deprecate.warned_methods[method_key]
33
+
34
+ replacement_text = replacement ? " (use #{replacement} instead)" : ""
35
+ caller_info = if Deprecate.config[:show_caller]
36
+ caller_location = caller_locations(3, 1)
37
+ caller_location && caller_location.first ? caller_location.first.to_s : "unknown"
38
+ else
39
+ "unknown"
40
+ end
41
+
42
+ message = Deprecate.config[:message_format] % {
43
+ method: method_name,
44
+ replacement: replacement_text,
45
+ caller: caller_info
46
+ }
47
+
48
+ Deprecate.config[:output_stream].puts(message)
49
+ Deprecate.warned_methods[method_key] = true if Deprecate.config[:warn_once]
50
+ end
51
+ def deprecate(sym, replacement=nil, scope=nil)
52
+ unless sym.is_a?(Symbol)
53
+ raise ArgumentError, 'deprecate() requires symbols for its first argument.'
54
+ end
55
+
56
+ meth = instance_method(sym)
57
+ unless scope
58
+ pub = public_instance_methods
59
+ pro = protected_instance_methods
60
+ pri = private_instance_methods
61
+ if pub.include?(sym) || pub.include?(sym.to_s)
62
+ scope = :public
63
+ elsif pro.include?(sym) || pro.include?(sym.to_s)
64
+ scope = :protected
65
+ elsif pri.include?(sym) || pri.include?(sym.to_s)
66
+ scope = :private
67
+ end
68
+ end
69
+
70
+ define_method(sym) do |*args|
71
+ __deprecated_run_action__(sym, replacement)
72
+ meth.bind(self).call(*args)
73
+ end
74
+
75
+ method(scope).call(sym) if scope
76
+ return scope
77
+ end
78
+ end
79
+ end
80
+
81
+ class Object
82
+ include Deprecate::Deprecatable
5
83
  end
@@ -0,0 +1,211 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Deprecate do
4
+ let(:output) { StringIO.new }
5
+
6
+ before do
7
+ Deprecate.reset_warnings!
8
+ Deprecate.configure do |config|
9
+ config[:output_stream] = output
10
+ config[:warn_once] = false
11
+ end
12
+ end
13
+
14
+ after do
15
+ Deprecate.configure do |config|
16
+ config[:output_stream] = $stderr
17
+ config[:warn_once] = true
18
+ end
19
+ end
20
+
21
+ describe '#deprecate' do
22
+ context 'with replacement method' do
23
+ let(:test_class) do
24
+ Class.new do
25
+ def old_method
26
+ "old result"
27
+ end
28
+
29
+ def new_method
30
+ "new result"
31
+ end
32
+
33
+ deprecate :old_method, :new_method
34
+ end
35
+ end
36
+
37
+ it 'returns the original method result' do
38
+ obj = test_class.new
39
+ expect(obj.old_method).to eq("old result")
40
+ end
41
+
42
+ it 'prints deprecation warning with replacement' do
43
+ obj = test_class.new
44
+ obj.old_method
45
+ expect(output.string).to match(/DEPRECATION WARNING: old_method is deprecated \(use new_method instead\)/)
46
+ end
47
+ end
48
+
49
+ context 'without replacement method' do
50
+ let(:test_class) do
51
+ Class.new do
52
+ def legacy_method
53
+ "legacy result"
54
+ end
55
+
56
+ deprecate :legacy_method
57
+ end
58
+ end
59
+
60
+ it 'returns the original method result' do
61
+ obj = test_class.new
62
+ expect(obj.legacy_method).to eq("legacy result")
63
+ end
64
+
65
+ it 'prints deprecation warning without replacement' do
66
+ obj = test_class.new
67
+ obj.legacy_method
68
+ expect(output.string).to match(/DEPRECATION WARNING: legacy_method is deprecated\./)
69
+ expect(output.string).not_to match(/use .* instead/)
70
+ end
71
+ end
72
+
73
+ context 'with method arguments' do
74
+ let(:test_class) do
75
+ Class.new do
76
+ def old_method(arg1, arg2)
77
+ "#{arg1}-#{arg2}"
78
+ end
79
+
80
+ deprecate :old_method, :new_method
81
+ end
82
+ end
83
+
84
+ it 'passes arguments correctly' do
85
+ obj = test_class.new
86
+ expect(obj.old_method("hello", "world")).to eq("hello-world")
87
+ end
88
+
89
+ it 'prints deprecation warning' do
90
+ obj = test_class.new
91
+ obj.old_method("hello", "world")
92
+ expect(output.string).to match(/DEPRECATION WARNING/)
93
+ end
94
+ end
95
+
96
+ context 'with private methods' do
97
+ let(:test_class) do
98
+ Class.new do
99
+ private
100
+
101
+ def private_method
102
+ "private result"
103
+ end
104
+
105
+ deprecate :private_method
106
+
107
+ public
108
+
109
+ def call_private
110
+ private_method
111
+ end
112
+ end
113
+ end
114
+
115
+ it 'preserves method visibility' do
116
+ obj = test_class.new
117
+ expect(obj.call_private).to eq("private result")
118
+ expect { obj.private_method }.to raise_error(NoMethodError)
119
+ end
120
+
121
+ it 'prints deprecation warning when called' do
122
+ obj = test_class.new
123
+ obj.call_private
124
+ expect(output.string).to match(/DEPRECATION WARNING: private_method is deprecated/)
125
+ end
126
+ end
127
+
128
+ context 'with invalid arguments' do
129
+ it 'raises ArgumentError for non-symbol arguments' do
130
+ expect {
131
+ Class.new do
132
+ deprecate "string_method"
133
+ end
134
+ }.to raise_error(ArgumentError, /deprecate\(\) requires symbols/)
135
+ end
136
+ end
137
+ end
138
+
139
+ describe 'configuration' do
140
+ context 'warn_once setting' do
141
+ before { Deprecate.configure { |config| config[:warn_once] = true } }
142
+
143
+ let(:test_class) do
144
+ Class.new do
145
+ def old_method
146
+ "result"
147
+ end
148
+
149
+ deprecate :old_method
150
+ end
151
+ end
152
+
153
+ it 'warns only once per method' do
154
+ obj = test_class.new
155
+ obj.old_method
156
+ obj.old_method
157
+
158
+ warnings = output.string.scan(/DEPRECATION WARNING/)
159
+ expect(warnings.length).to eq(1)
160
+ end
161
+ end
162
+
163
+ context 'custom message format' do
164
+ before do
165
+ Deprecate.configure do |config|
166
+ config[:message_format] = "CUSTOM: %{method} is old%{replacement}"
167
+ config[:show_caller] = false
168
+ end
169
+ end
170
+
171
+ let(:test_class) do
172
+ Class.new do
173
+ def old_method
174
+ "result"
175
+ end
176
+
177
+ deprecate :old_method, :new_method
178
+ end
179
+ end
180
+
181
+ it 'uses custom message format' do
182
+ obj = test_class.new
183
+ obj.old_method
184
+ expect(output.string).to match(/CUSTOM: old_method is old \(use new_method instead\)/)
185
+ end
186
+ end
187
+ end
188
+
189
+ describe '.reset_warnings!' do
190
+ it 'clears the warned methods hash' do
191
+ # Just test that the hash gets cleared
192
+ Deprecate.configure { |config| config[:warn_once] = true }
193
+
194
+ # Add a warning to the hash
195
+ test_class = Class.new do
196
+ def old_method
197
+ "result"
198
+ end
199
+ deprecate :old_method
200
+ end
201
+
202
+ obj = test_class.new
203
+ obj.old_method # This should add to warned_methods hash
204
+
205
+ expect(Deprecate.warned_methods).not_to be_empty
206
+
207
+ Deprecate.reset_warnings!
208
+ expect(Deprecate.warned_methods).to be_empty
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,14 @@
1
+ require 'stringio'
2
+ require_relative '../lib/deprecate'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+
13
+ config.shared_context_metadata_behavior = :apply_to_host_groups
14
+ end
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ require 'stringio'
3
+ require_relative '../lib/deprecate'
4
+
5
+ def assert_equal(expected, actual, message = nil)
6
+ unless expected == actual
7
+ raise "Assertion failed#{message ? ": #{message}" : ""}\n Expected: #{expected.inspect}\n Actual: #{actual.inspect}"
8
+ end
9
+ end
10
+
11
+ def assert_match(pattern, string, message = nil)
12
+ unless pattern.match?(string)
13
+ raise "Assertion failed#{message ? ": #{message}" : ""}\n Pattern: #{pattern.inspect}\n String: #{string.inspect}"
14
+ end
15
+ end
16
+
17
+ def refute_match(pattern, string, message = nil)
18
+ if pattern.match?(string)
19
+ raise "Assertion failed#{message ? ": #{message}" : ""}\n Pattern should NOT match: #{pattern.inspect}\n String: #{string.inspect}"
20
+ end
21
+ end
22
+
23
+ # Setup
24
+ def setup_test
25
+ Deprecate.reset_warnings!
26
+ output = StringIO.new
27
+ Deprecate.configure do |config|
28
+ config[:output_stream] = output
29
+ config[:warn_once] = false
30
+ end
31
+ output
32
+ end
33
+
34
+ def teardown_test
35
+ Deprecate.configure do |config|
36
+ config[:output_stream] = $stderr
37
+ config[:warn_once] = true
38
+ end
39
+ end
40
+
41
+ puts "Running basic deprecation tests..."
42
+
43
+ # Test 1: Basic deprecation
44
+ output = setup_test
45
+
46
+ klass = Class.new do
47
+ def old_method
48
+ "old result"
49
+ end
50
+
51
+ deprecate :old_method, :new_method
52
+ end
53
+
54
+ obj = klass.new
55
+ result = obj.old_method
56
+
57
+ assert_equal "old result", result
58
+ assert_match(/DEPRECATION WARNING: old_method is deprecated/, output.string)
59
+ puts "✓ Basic deprecation test passed"
60
+
61
+ teardown_test
62
+
63
+ # Test 2: Without replacement
64
+ output = setup_test
65
+
66
+ klass2 = Class.new do
67
+ def legacy_method
68
+ "legacy"
69
+ end
70
+
71
+ deprecate :legacy_method
72
+ end
73
+
74
+ obj2 = klass2.new
75
+ result2 = obj2.legacy_method
76
+
77
+ assert_equal "legacy", result2
78
+ assert_match(/DEPRECATION WARNING: legacy_method is deprecated/, output.string)
79
+ refute_match(/use .* instead/, output.string)
80
+ puts "✓ Deprecation without replacement test passed"
81
+
82
+ teardown_test
83
+
84
+ # Test 3: Method with arguments
85
+ output = setup_test
86
+
87
+ klass3 = Class.new do
88
+ def old_method(arg1, arg2)
89
+ "#{arg1}-#{arg2}"
90
+ end
91
+
92
+ deprecate :old_method
93
+ end
94
+
95
+ obj3 = klass3.new
96
+ result3 = obj3.old_method("hello", "world")
97
+
98
+ assert_equal "hello-world", result3
99
+ assert_match(/DEPRECATION WARNING/, output.string)
100
+ puts "✓ Method with arguments test passed"
101
+
102
+ teardown_test
103
+
104
+ # Test 4: Warn once functionality
105
+ output = setup_test
106
+ Deprecate.configure { |config| config[:warn_once] = true }
107
+
108
+ klass4 = Class.new do
109
+ def old_method
110
+ "result"
111
+ end
112
+
113
+ deprecate :old_method
114
+ end
115
+
116
+ obj4 = klass4.new
117
+ obj4.old_method
118
+ obj4.old_method
119
+
120
+ warnings_count = output.string.scan(/DEPRECATION WARNING/).length
121
+ assert_equal 1, warnings_count
122
+ puts "✓ Warn once functionality test passed"
123
+
124
+ teardown_test
125
+
126
+ puts "\nAll tests passed! ✅"
@@ -0,0 +1,167 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/deprecate'
3
+
4
+ class TestDeprecate < Minitest::Test
5
+ def setup
6
+ Deprecate.reset_warnings!
7
+ @output = StringIO.new
8
+ Deprecate.configure do |config|
9
+ config[:output_stream] = @output
10
+ config[:warn_once] = false
11
+ end
12
+ end
13
+
14
+ def teardown
15
+ Deprecate.configure do |config|
16
+ config[:output_stream] = $stderr
17
+ config[:warn_once] = true
18
+ end
19
+ end
20
+
21
+ def test_deprecate_method_with_replacement
22
+ klass = Class.new do
23
+ def old_method
24
+ "old result"
25
+ end
26
+
27
+ def new_method
28
+ "new result"
29
+ end
30
+
31
+ deprecate :old_method, :new_method
32
+ end
33
+
34
+ obj = klass.new
35
+ result = obj.old_method
36
+
37
+ assert_equal "old result", result
38
+ assert_match(/DEPRECATION WARNING: old_method is deprecated \(use new_method instead\)/, @output.string)
39
+ end
40
+
41
+ def test_deprecate_method_without_replacement
42
+ klass = Class.new do
43
+ def old_method
44
+ "old result"
45
+ end
46
+
47
+ deprecate :old_method
48
+ end
49
+
50
+ obj = klass.new
51
+ result = obj.old_method
52
+
53
+ assert_equal "old result", result
54
+ assert_match(/DEPRECATION WARNING: old_method is deprecated\. Called from/, @output.string)
55
+ refute_match(/use .* instead/, @output.string)
56
+ end
57
+
58
+ def test_deprecate_with_arguments
59
+ klass = Class.new do
60
+ def old_method(arg1, arg2)
61
+ "#{arg1}-#{arg2}"
62
+ end
63
+
64
+ deprecate :old_method, :new_method
65
+ end
66
+
67
+ obj = klass.new
68
+ result = obj.old_method("hello", "world")
69
+
70
+ assert_equal "hello-world", result
71
+ assert_match(/DEPRECATION WARNING/, @output.string)
72
+ end
73
+
74
+ def test_deprecate_preserves_method_scope
75
+ klass = Class.new do
76
+ private
77
+
78
+ def private_method
79
+ "private result"
80
+ end
81
+
82
+ deprecate :private_method
83
+
84
+ public
85
+
86
+ def call_private
87
+ private_method
88
+ end
89
+ end
90
+
91
+ obj = klass.new
92
+ result = obj.call_private
93
+
94
+ assert_equal "private result", result
95
+ assert_raises(NoMethodError) { obj.private_method }
96
+ end
97
+
98
+ def test_warn_once_configuration
99
+ Deprecate.configure { |config| config[:warn_once] = true }
100
+
101
+ klass = Class.new do
102
+ def old_method
103
+ "result"
104
+ end
105
+
106
+ deprecate :old_method
107
+ end
108
+
109
+ obj = klass.new
110
+ obj.old_method
111
+ obj.old_method
112
+
113
+ assert_equal 1, @output.string.scan(/DEPRECATION WARNING/).length
114
+ end
115
+
116
+ def test_reset_warnings
117
+ Deprecate.configure { |config| config[:warn_once] = true }
118
+
119
+ klass = Class.new do
120
+ def old_method
121
+ "result"
122
+ end
123
+
124
+ deprecate :old_method
125
+ end
126
+
127
+ obj = klass.new
128
+ obj.old_method
129
+ Deprecate.reset_warnings!
130
+ obj.old_method
131
+
132
+ assert_equal 2, @output.string.scan(/DEPRECATION WARNING/).length
133
+ end
134
+
135
+ def test_invalid_symbol_argument
136
+ klass = Class.new
137
+
138
+ assert_raises(ArgumentError, "deprecate() requires symbols for its first argument.") do
139
+ klass.class_eval do
140
+ deprecate "string_method"
141
+ end
142
+ end
143
+ end
144
+
145
+ def test_custom_message_format
146
+ original_format = Deprecate.config[:message_format]
147
+ Deprecate.configure do |config|
148
+ config[:message_format] = "CUSTOM: %{method} is old%{replacement}"
149
+ config[:show_caller] = false
150
+ end
151
+
152
+ klass = Class.new do
153
+ def old_method
154
+ "result"
155
+ end
156
+
157
+ deprecate :old_method, :new_method
158
+ end
159
+
160
+ obj = klass.new
161
+ obj.old_method
162
+
163
+ assert_match(/CUSTOM: old_method is old \(use new_method instead\)/, @output.string)
164
+
165
+ Deprecate.configure { |config| config[:message_format] = original_format }
166
+ end
167
+ end
@@ -0,0 +1,107 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+ require_relative '../lib/deprecate'
4
+
5
+ class TestDeprecate < Minitest::Test
6
+ def setup
7
+ Deprecate.reset_warnings!
8
+ @output = StringIO.new
9
+ Deprecate.configure do |config|
10
+ config[:output_stream] = @output
11
+ config[:warn_once] = false
12
+ end
13
+ end
14
+
15
+ def teardown
16
+ Deprecate.configure do |config|
17
+ config[:output_stream] = $stderr
18
+ config[:warn_once] = true
19
+ end
20
+ end
21
+
22
+ def test_basic_deprecation
23
+ klass = Class.new do
24
+ def old_method
25
+ "old result"
26
+ end
27
+
28
+ deprecate :old_method, :new_method
29
+ end
30
+
31
+ obj = klass.new
32
+ result = obj.old_method
33
+
34
+ assert_equal "old result", result
35
+ assert_match(/DEPRECATION WARNING: old_method is deprecated/, @output.string)
36
+ end
37
+
38
+ def test_deprecation_without_replacement
39
+ klass = Class.new do
40
+ def legacy_method
41
+ "legacy"
42
+ end
43
+
44
+ deprecate :legacy_method
45
+ end
46
+
47
+ obj = klass.new
48
+ result = obj.legacy_method
49
+
50
+ assert_equal "legacy", result
51
+ assert_match(/DEPRECATION WARNING: legacy_method is deprecated/, @output.string)
52
+ refute_match(/use .* instead/, @output.string)
53
+ end
54
+
55
+ def test_method_with_arguments
56
+ klass = Class.new do
57
+ def old_method(arg1, arg2)
58
+ "#{arg1}-#{arg2}"
59
+ end
60
+
61
+ deprecate :old_method
62
+ end
63
+
64
+ obj = klass.new
65
+ result = obj.old_method("hello", "world")
66
+
67
+ assert_equal "hello-world", result
68
+ assert_match(/DEPRECATION WARNING/, @output.string)
69
+ end
70
+
71
+ def test_warn_once_functionality
72
+ Deprecate.configure { |config| config[:warn_once] = true }
73
+
74
+ klass = Class.new do
75
+ def old_method
76
+ "result"
77
+ end
78
+
79
+ deprecate :old_method
80
+ end
81
+
82
+ obj = klass.new
83
+ obj.old_method
84
+ obj.old_method
85
+
86
+ assert_equal 1, @output.string.scan(/DEPRECATION WARNING/).length
87
+ end
88
+
89
+ def test_reset_warnings
90
+ Deprecate.configure { |config| config[:warn_once] = true }
91
+
92
+ klass = Class.new do
93
+ def old_method
94
+ "result"
95
+ end
96
+
97
+ deprecate :old_method
98
+ end
99
+
100
+ obj = klass.new
101
+ obj.old_method
102
+ Deprecate.reset_warnings!
103
+ obj.old_method
104
+
105
+ assert_equal 2, @output.string.scan(/DEPRECATION WARNING/).length
106
+ end
107
+ end
data/test_manual.rb ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative 'lib/deprecate'
3
+
4
+ # Simple test to verify the gem works
5
+ class TestClass
6
+ def old_method(name = "world")
7
+ "Hello, #{name}!"
8
+ end
9
+
10
+ def new_method(name = "world")
11
+ "Hi there, #{name}!"
12
+ end
13
+
14
+ deprecate :old_method, :new_method
15
+ end
16
+
17
+ puts "Testing basic functionality..."
18
+ obj = TestClass.new
19
+
20
+ puts "Calling deprecated method:"
21
+ result = obj.old_method("Claude")
22
+ puts "Result: #{result}"
23
+
24
+ puts "\nCalling again (should warn only once by default):"
25
+ result2 = obj.old_method("again")
26
+ puts "Result: #{result2}"
27
+
28
+ puts "\nResetting warnings and calling again:"
29
+ Deprecate.reset_warnings!
30
+ result3 = obj.old_method("reset")
31
+ puts "Result: #{result3}"
32
+
33
+ puts "\nTesting without replacement:"
34
+ class TestClass2
35
+ def legacy_method
36
+ "legacy"
37
+ end
38
+
39
+ deprecate :legacy_method
40
+ end
41
+
42
+ obj2 = TestClass2.new
43
+ result4 = obj2.legacy_method
44
+ puts "Legacy result: #{result4}"
45
+
46
+ puts "\nAll tests completed successfully!"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
10
+ date: 2025-08-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -16,36 +15,54 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.7'
18
+ version: '2.0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.7'
25
+ version: '2.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- description:
39
+ version: '13.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
42
54
  email:
43
55
  - dale@twilightcoder.net
44
56
  executables: []
45
57
  extensions: []
46
58
  extra_rdoc_files: []
47
59
  files:
60
+ - ".github/workflows/ci.yml"
48
61
  - ".gitignore"
62
+ - ".qlty.toml"
63
+ - ".reek.yml"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
49
66
  - Gemfile
50
67
  - LICENSE.txt
51
68
  - README.md
@@ -53,11 +70,16 @@ files:
53
70
  - deprecate.gemspec
54
71
  - lib/deprecate.rb
55
72
  - lib/deprecate/version.rb
56
- homepage: ''
73
+ - spec/deprecate_spec.rb
74
+ - spec/spec_helper.rb
75
+ - test/test_basic.rb
76
+ - test/test_deprecate.rb
77
+ - test/test_deprecate_simple.rb
78
+ - test_manual.rb
79
+ homepage: https://github.com/twilightcoders/deprecate
57
80
  licenses:
58
81
  - MIT
59
82
  metadata: {}
60
- post_install_message:
61
83
  rdoc_options: []
62
84
  require_paths:
63
85
  - lib
@@ -65,17 +87,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
87
  requirements:
66
88
  - - ">="
67
89
  - !ruby/object:Gem::Version
68
- version: '0'
90
+ version: 2.7.0
69
91
  required_rubygems_version: !ruby/object:Gem::Requirement
70
92
  requirements:
71
93
  - - ">="
72
94
  - !ruby/object:Gem::Version
73
95
  version: '0'
74
96
  requirements: []
75
- rubyforge_project:
76
- rubygems_version: 2.2.2
77
- signing_key:
97
+ rubygems_version: 3.6.3
78
98
  specification_version: 4
79
99
  summary: Easily maintain your codebase by exposing an easy and concise way to mark
80
100
  methods as deprecated.
81
- test_files: []
101
+ test_files:
102
+ - spec/deprecate_spec.rb
103
+ - spec/spec_helper.rb
104
+ - test/test_basic.rb
105
+ - test/test_deprecate.rb
106
+ - test/test_deprecate_simple.rb