uncruft 0.2.1 → 0.3.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 +4 -4
- data/Rakefile +10 -8
- data/lib/uncruft/deprecation_handler.rb +12 -12
- data/lib/uncruft/version.rb +1 -1
- data/lib/uncruft/warning.rb +3 -1
- data/lib/uncruft.rb +5 -2
- metadata +20 -39
- data/spec/dummy/config/application.rb +0 -8
- data/spec/dummy/config/deprecations.ignore +0 -7
- data/spec/examples.txt +0 -28
- data/spec/spec_helper.rb +0 -13
- data/spec/support/rails_root.rb +0 -7
- data/spec/uncruft/deprecatable_spec.rb +0 -58
- data/spec/uncruft/deprecation_handler_spec.rb +0 -172
- data/spec/uncruft/railtie_spec.rb +0 -33
- data/spec/uncruft/warning_spec.rb +0 -46
- data/spec/uncruft_spec.rb +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2cab324dae5f8b3fc23c4f99785900af558ab66cee8a908222b3e7793482a35
|
|
4
|
+
data.tar.gz: 65ce169801afae62f4bd2b005b0ec901416c7f1372c2c5ca48a8ca3a9e9b79b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d8f03d9ae4074f0097facfa7f20895ef17ec72082ba4f2a2fa49ddc8dfef688a7574f2fab60d134a42e60fa0ef841ce9201a9226da3e0dc9bd239737d260a88
|
|
7
|
+
data.tar.gz: 6f5857f50049b5016bb96d3e106de7c5a54818625c7922de2cb2b1971b857118af64bdf19a414694862b77d22b5a015c7f908ecc683899c8df5a4dc743ce14de
|
data/Rakefile
CHANGED
|
@@ -6,8 +6,6 @@ end
|
|
|
6
6
|
|
|
7
7
|
Bundler::GemHelper.install_tasks
|
|
8
8
|
|
|
9
|
-
task(:default).clear
|
|
10
|
-
|
|
11
9
|
require 'rubocop/rake_task'
|
|
12
10
|
RuboCop::RakeTask.new
|
|
13
11
|
|
|
@@ -15,10 +13,14 @@ require 'rspec/core'
|
|
|
15
13
|
require 'rspec/core/rake_task'
|
|
16
14
|
RSpec::Core::RakeTask.new(:spec)
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
def default_task
|
|
17
|
+
if ENV['APPRAISAL_INITIALIZED'] || ENV['CI']
|
|
18
|
+
%i(rubocop spec)
|
|
19
|
+
else
|
|
20
|
+
require 'appraisal'
|
|
21
|
+
Appraisal::Task.new
|
|
22
|
+
%i(appraisal)
|
|
23
|
+
end
|
|
24
24
|
end
|
|
25
|
+
|
|
26
|
+
task(:default).clear.enhance(default_task)
|
|
@@ -41,9 +41,11 @@ module Uncruft
|
|
|
41
41
|
|
|
42
42
|
def normalize_callstack_path(message)
|
|
43
43
|
if (gem_home = gem_home(message)).present?
|
|
44
|
-
message.gsub(gem_home, '$GEM_PATH')
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
message.gsub!(gem_home, '$GEM_PATH')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if (absolute_path = absolute_path(message)).present?
|
|
48
|
+
message.gsub!(absolute_path, relative_path(absolute_path))
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
|
|
@@ -64,7 +66,7 @@ module Uncruft
|
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
def gem_home(message)
|
|
67
|
-
message.match(%r{
|
|
69
|
+
message.match(%r{(?i:c)alled from( .+ at)? (#{ENV['GEM_HOME']}/(.+/)*gems)})&.[](2) # rubocop:disable Style/FetchEnvVar
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def absolute_path(message)
|
|
@@ -95,14 +97,12 @@ module Uncruft
|
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
def known_deprecations
|
|
98
|
-
@known_deprecations ||=
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
end
|
|
105
|
-
end
|
|
100
|
+
@known_deprecations ||= if known_deprecations_file_exists?
|
|
101
|
+
file = File.read(Uncruft.ignorefile_path)
|
|
102
|
+
JSON.parse(file)['ignored_warnings'].to_set
|
|
103
|
+
else
|
|
104
|
+
Set.new
|
|
105
|
+
end
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
def file_content(deprecations)
|
data/lib/uncruft/version.rb
CHANGED
data/lib/uncruft/warning.rb
CHANGED
|
@@ -2,10 +2,12 @@ module Uncruft
|
|
|
2
2
|
module Warning
|
|
3
3
|
DEPRECATION_PATTERN = /(deprecation|deprecated)/i.freeze
|
|
4
4
|
|
|
5
|
-
def warn(str, *args)
|
|
5
|
+
def warn(str, *args, **kwargs)
|
|
6
6
|
if str =~ DEPRECATION_PATTERN # rubocop:disable Performance/RegexpMatch
|
|
7
7
|
message = strip_caller_info(str, caller_locations(1..1).first).strip
|
|
8
8
|
ActiveSupport::Deprecation.warn(message)
|
|
9
|
+
elsif RUBY_VERSION < '2.7' && kwargs.empty?
|
|
10
|
+
super(str, *args)
|
|
9
11
|
else
|
|
10
12
|
super
|
|
11
13
|
end
|
data/lib/uncruft.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'active_support/time'
|
|
3
|
+
|
|
1
4
|
require 'uncruft/version'
|
|
2
5
|
require 'uncruft/railtie'
|
|
3
6
|
require 'uncruft/deprecation_handler'
|
|
@@ -10,11 +13,11 @@ module Uncruft
|
|
|
10
13
|
FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
|
|
11
14
|
|
|
12
15
|
def record_deprecations?
|
|
13
|
-
ENV['RECORD_DEPRECATIONS'].presence && !
|
|
16
|
+
ENV['RECORD_DEPRECATIONS'].presence && !ENV['RECORD_DEPRECATIONS'].in?(FALSE_VALUES)
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def ignorefile_path
|
|
17
|
-
ENV['UNCRUFT_IGNOREFILE_PATH'] || Rails.root.join('config
|
|
20
|
+
ENV['UNCRUFT_IGNOREFILE_PATH'] || Rails.root.join('config/deprecations.ignore')
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uncruft
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Griffith
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2023-04-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: railties
|
|
@@ -17,14 +17,14 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 5.2.0
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 5.2.0
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: appraisal
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -40,7 +40,7 @@ dependencies:
|
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
41
|
version: 2.2.0
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
|
-
name:
|
|
43
|
+
name: betterlint
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
@@ -54,33 +54,33 @@ dependencies:
|
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '0'
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
|
-
name:
|
|
57
|
+
name: rails
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
|
-
- - "
|
|
60
|
+
- - ">="
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version:
|
|
62
|
+
version: '0'
|
|
63
63
|
type: :development
|
|
64
64
|
prerelease: false
|
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
|
-
- - "
|
|
67
|
+
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
69
|
+
version: '0'
|
|
70
70
|
- !ruby/object:Gem::Dependency
|
|
71
|
-
name:
|
|
71
|
+
name: rspec
|
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
|
-
- - "
|
|
74
|
+
- - "~>"
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version:
|
|
76
|
+
version: 3.7.0
|
|
77
77
|
type: :development
|
|
78
78
|
prerelease: false
|
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
|
81
|
-
- - "
|
|
81
|
+
- - "~>"
|
|
82
82
|
- !ruby/object:Gem::Version
|
|
83
|
-
version:
|
|
83
|
+
version: 3.7.0
|
|
84
84
|
- !ruby/object:Gem::Dependency
|
|
85
85
|
name: timecop
|
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -112,20 +112,11 @@ files:
|
|
|
112
112
|
- lib/uncruft/railtie.rb
|
|
113
113
|
- lib/uncruft/version.rb
|
|
114
114
|
- lib/uncruft/warning.rb
|
|
115
|
-
- spec/dummy/config/application.rb
|
|
116
|
-
- spec/dummy/config/deprecations.ignore
|
|
117
|
-
- spec/examples.txt
|
|
118
|
-
- spec/spec_helper.rb
|
|
119
|
-
- spec/support/rails_root.rb
|
|
120
|
-
- spec/uncruft/deprecatable_spec.rb
|
|
121
|
-
- spec/uncruft/deprecation_handler_spec.rb
|
|
122
|
-
- spec/uncruft/railtie_spec.rb
|
|
123
|
-
- spec/uncruft/warning_spec.rb
|
|
124
|
-
- spec/uncruft_spec.rb
|
|
125
115
|
homepage: https://github.com/Betterment/uncruft
|
|
126
116
|
licenses:
|
|
127
117
|
- MIT
|
|
128
|
-
metadata:
|
|
118
|
+
metadata:
|
|
119
|
+
rubygems_mfa_required: 'true'
|
|
129
120
|
post_install_message:
|
|
130
121
|
rdoc_options: []
|
|
131
122
|
require_paths:
|
|
@@ -134,25 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
134
125
|
requirements:
|
|
135
126
|
- - ">="
|
|
136
127
|
- !ruby/object:Gem::Version
|
|
137
|
-
version:
|
|
128
|
+
version: 2.6.0
|
|
138
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
130
|
requirements:
|
|
140
131
|
- - ">="
|
|
141
132
|
- !ruby/object:Gem::Version
|
|
142
133
|
version: '0'
|
|
143
134
|
requirements: []
|
|
144
|
-
rubygems_version: 3.
|
|
135
|
+
rubygems_version: 3.3.5
|
|
145
136
|
signing_key:
|
|
146
137
|
specification_version: 4
|
|
147
138
|
summary: A library to assist with Rails upgrades
|
|
148
|
-
test_files:
|
|
149
|
-
- spec/spec_helper.rb
|
|
150
|
-
- spec/dummy/config/deprecations.ignore
|
|
151
|
-
- spec/dummy/config/application.rb
|
|
152
|
-
- spec/examples.txt
|
|
153
|
-
- spec/uncruft/railtie_spec.rb
|
|
154
|
-
- spec/uncruft/warning_spec.rb
|
|
155
|
-
- spec/uncruft/deprecatable_spec.rb
|
|
156
|
-
- spec/uncruft/deprecation_handler_spec.rb
|
|
157
|
-
- spec/support/rails_root.rb
|
|
158
|
-
- spec/uncruft_spec.rb
|
|
139
|
+
test_files: []
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
|
2
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
|
4
|
-
|
|
5
|
-
module Dummy
|
|
6
|
-
class Application < Rails::Application
|
|
7
|
-
end
|
|
8
|
-
end
|
data/spec/examples.txt
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
example_id | status | run_time |
|
|
2
|
-
------------------------------------------------------- | ------ | --------------- |
|
|
3
|
-
./spec/uncruft/deprecatable_spec.rb[1:1:1] | passed | 0.00763 seconds |
|
|
4
|
-
./spec/uncruft/deprecatable_spec.rb[1:1:2] | passed | 0.00031 seconds |
|
|
5
|
-
./spec/uncruft/deprecatable_spec.rb[1:2:1] | passed | 0.00025 seconds |
|
|
6
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:1] | passed | 0.00536 seconds |
|
|
7
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:2:1] | passed | 0.00786 seconds |
|
|
8
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:2:2:1] | passed | 0.00347 seconds |
|
|
9
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:3:1] | passed | 0.00061 seconds |
|
|
10
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:4:1] | passed | 0.00039 seconds |
|
|
11
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:5:1] | passed | 0.00044 seconds |
|
|
12
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:6:1] | passed | 0.00054 seconds |
|
|
13
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:6:2:1] | passed | 0.00045 seconds |
|
|
14
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:6:3:1] | passed | 0.00058 seconds |
|
|
15
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:6:3:2:1] | passed | 0.00066 seconds |
|
|
16
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:7:1] | passed | 0.00047 seconds |
|
|
17
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:8:1] | passed | 0.00302 seconds |
|
|
18
|
-
./spec/uncruft/deprecation_handler_spec.rb[1:1:8:2:1] | passed | 0.00166 seconds |
|
|
19
|
-
./spec/uncruft/railtie_spec.rb[1:1] | passed | 0.04267 seconds |
|
|
20
|
-
./spec/uncruft/railtie_spec.rb[1:2:1] | passed | 0.00167 seconds |
|
|
21
|
-
./spec/uncruft/railtie_spec.rb[1:3:1] | passed | 0.00219 seconds |
|
|
22
|
-
./spec/uncruft/warning_spec.rb[1:1] | passed | 0.00031 seconds |
|
|
23
|
-
./spec/uncruft/warning_spec.rb[1:2] | passed | 0.00011 seconds |
|
|
24
|
-
./spec/uncruft/warning_spec.rb[1:3:1] | passed | 0.00054 seconds |
|
|
25
|
-
./spec/uncruft/warning_spec.rb[1:3:2:1] | passed | 0.00045 seconds |
|
|
26
|
-
./spec/uncruft_spec.rb[1:1:1] | passed | 0.00246 seconds |
|
|
27
|
-
./spec/uncruft_spec.rb[1:2:1] | passed | 0.00025 seconds |
|
|
28
|
-
./spec/uncruft_spec.rb[1:2:2:1] | passed | 0.00024 seconds |
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'bundler'
|
|
2
|
-
Bundler.require :default, :development
|
|
3
|
-
|
|
4
|
-
ENV["RAILS_ENV"] ||= 'test'
|
|
5
|
-
require File.expand_path('dummy/config/application', __dir__)
|
|
6
|
-
require 'support/rails_root'
|
|
7
|
-
|
|
8
|
-
Time.zone = ActiveSupport::TimeZone.all.first
|
|
9
|
-
|
|
10
|
-
RSpec.configure do |config|
|
|
11
|
-
config.run_all_when_everything_filtered = true
|
|
12
|
-
config.example_status_persistence_file_path = 'spec/examples.txt'
|
|
13
|
-
end
|
data/spec/support/rails_root.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Uncruft::Deprecatable do
|
|
4
|
-
let(:my_name) { "Jess" }
|
|
5
|
-
|
|
6
|
-
subject { klass.new }
|
|
7
|
-
|
|
8
|
-
describe '.deprecate_attribute' do
|
|
9
|
-
let(:klass) do
|
|
10
|
-
Class.new do
|
|
11
|
-
include Uncruft::Deprecatable
|
|
12
|
-
|
|
13
|
-
attr_accessor :first_name
|
|
14
|
-
|
|
15
|
-
deprecate_attribute(:first_name,
|
|
16
|
-
message: "Please stop using this attribute!")
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'applies deprecation warning when setting deprecated attribute' do
|
|
21
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).once
|
|
22
|
-
.with("Please stop using this attribute!")
|
|
23
|
-
|
|
24
|
-
expect(subject.first_name = my_name).to eq my_name
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'applies deprecation warning when getting deprecated attribute' do
|
|
28
|
-
subject.instance_variable_set(:@first_name, my_name)
|
|
29
|
-
|
|
30
|
-
expect(ActiveSupport::Deprecation).to receive(:warn)
|
|
31
|
-
.with("Please stop using this attribute!")
|
|
32
|
-
|
|
33
|
-
expect(subject.first_name).to eq my_name
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe '.deprecate_method' do
|
|
38
|
-
let(:klass) do
|
|
39
|
-
Class.new do
|
|
40
|
-
include Uncruft::Deprecatable
|
|
41
|
-
|
|
42
|
-
def legacy_method
|
|
43
|
-
"Hello Old World!"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
deprecate_method(:legacy_method,
|
|
47
|
-
message: "Please stop using this method!")
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'applies deprecation warning when calling the deprecated method' do
|
|
52
|
-
expect(ActiveSupport::Deprecation).to receive(:warn)
|
|
53
|
-
.with("Please stop using this method!")
|
|
54
|
-
|
|
55
|
-
expect(subject.legacy_method).to eq "Hello Old World!"
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Uncruft::DeprecationHandler do
|
|
4
|
-
let(:ignorefile_path) { Rails.root.join('config', 'deprecations.ignore') }
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
File.delete(ignorefile_path) if File.exist?(ignorefile_path)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
subject { described_class.new }
|
|
11
|
-
|
|
12
|
-
describe '#call' do
|
|
13
|
-
let(:absolute_path) { Rails.root.join('chicken', 'nuggets.rb') }
|
|
14
|
-
let(:line_number) { 123 }
|
|
15
|
-
let(:caller_label) { '<something>' }
|
|
16
|
-
let(:message) { "Warning: BAD called from #{caller_label} at #{absolute_path}:#{line_number}" }
|
|
17
|
-
let(:expected_ignorefile_entry) { 'Warning: BAD called from <something> at chicken/nuggets.rb' }
|
|
18
|
-
let(:expected_error) { "#{expected_ignorefile_entry}:123" }
|
|
19
|
-
let(:expected_error_message) do
|
|
20
|
-
<<~ERROR.strip
|
|
21
|
-
#{expected_error}
|
|
22
|
-
|
|
23
|
-
To resolve this error, adjust your code according to the instructions above.
|
|
24
|
-
If you did not introduce this error or are unsure why you are seeing it,
|
|
25
|
-
you will find additional guidance at the URL below:
|
|
26
|
-
https://github.com/Betterment/uncruft/blob/main/GUIDE.md
|
|
27
|
-
ERROR
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'sanitizes the message and raises an error' do
|
|
31
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when recording new deprecations' do
|
|
35
|
-
before do
|
|
36
|
-
allow(Uncruft).to receive(:record_deprecations?).and_return(true)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'sanitizes the message and writes it to the file' do
|
|
40
|
-
expect { subject.call(message, '') }.to change { File.exist?(ignorefile_path) }.from(false).to(true)
|
|
41
|
-
expect(File.read(ignorefile_path)).to include(expected_ignorefile_entry)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'when timecop is enabled' do
|
|
45
|
-
let(:test_started) { Time.zone.now }
|
|
46
|
-
|
|
47
|
-
it 'ignores time travel and writes the current time' do
|
|
48
|
-
Timecop.travel(test_started - 100.years) do
|
|
49
|
-
subject.call(message, '')
|
|
50
|
-
|
|
51
|
-
file_updated = Time.zone.parse(JSON.parse(File.read(ignorefile_path))['updated'])
|
|
52
|
-
expect(file_updated).to be_within(1.second).of(test_started)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'when caller is an erb file' do
|
|
59
|
-
let(:caller_label) { '_app_views_bananas_show__1234_567890' }
|
|
60
|
-
let(:expected_ignorefile_entry) { 'Warning: BAD called from chicken/nuggets.rb' }
|
|
61
|
-
|
|
62
|
-
it 'sanitizes the message and raises an error' do
|
|
63
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context 'when caller is "top (required)"' do
|
|
68
|
-
let(:caller_label) { '<top (required)>' }
|
|
69
|
-
let(:expected_ignorefile_entry) { 'Warning: BAD called from <global scope> at chicken/nuggets.rb' }
|
|
70
|
-
|
|
71
|
-
it 'sanitizes the caller and raises an error' do
|
|
72
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context 'when caller is "main"' do
|
|
77
|
-
let(:caller_label) { '<main>' }
|
|
78
|
-
let(:expected_ignorefile_entry) { 'Warning: BAD called from <global scope> at chicken/nuggets.rb' }
|
|
79
|
-
|
|
80
|
-
it 'sanitizes the caller and raises an error' do
|
|
81
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context 'when message includes custom gem path' do
|
|
86
|
-
let(:absolute_path) { Pathname.new('/banana/banana/banana/gems/chicken/nuggets.rb') }
|
|
87
|
-
let(:expected_ignorefile_entry) { "Warning: BAD called from <something> at $GEM_PATH/chicken/nuggets.rb" }
|
|
88
|
-
|
|
89
|
-
before do
|
|
90
|
-
allow(ENV).to receive(:[]).and_call_original
|
|
91
|
-
allow(ENV).to receive(:[]).with('GEM_HOME').and_return('/banana/banana/banana')
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'sanitizes the message and raises an error' do
|
|
95
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context 'when gem home is nested' do
|
|
99
|
-
let(:absolute_path) { Pathname.new('/banana/banana/banana/arbitrary/gem/path/gems/chicken/nuggets.rb') }
|
|
100
|
-
|
|
101
|
-
it 'sanitizes the message and raises an error' do
|
|
102
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
context 'when gem is vendored' do
|
|
107
|
-
let(:absolute_path) { Rails.root.join('vendor', 'cache', 'chicken', 'nuggets.rb') }
|
|
108
|
-
|
|
109
|
-
it 'sanitizes the message and raises an error' do
|
|
110
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context 'when gem is vendored elsewhere' do
|
|
114
|
-
let(:absolute_path) { Rails.root.join('..', '..', 'vendor', 'cache', 'chicken', 'nuggets.rb') }
|
|
115
|
-
|
|
116
|
-
it 'sanitizes the message and raises an error' do
|
|
117
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
context 'when caller is not a filepath' do
|
|
124
|
-
let(:absolute_path) { '(pry)' }
|
|
125
|
-
let(:expected_ignorefile_entry) { 'Warning: BAD called from <something> at (pry)' }
|
|
126
|
-
|
|
127
|
-
it 'sanitizes the message and raises an error' do
|
|
128
|
-
expect { subject.call(message, '') }.to raise_error(RuntimeError, expected_error_message)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
context 'when ignorefile exists' do
|
|
133
|
-
let(:message) { "Warning: BAD called from #{absolute_path}:#{line_number}" }
|
|
134
|
-
let(:file_content) do
|
|
135
|
-
<<~IGNOREFILE
|
|
136
|
-
{
|
|
137
|
-
"ignored_warnings": [
|
|
138
|
-
"Warning: BAD called from chicken/nuggets.rb"
|
|
139
|
-
],
|
|
140
|
-
"updated": "2018-06-05 15:20:12 -0400",
|
|
141
|
-
"rails_version": "5.1.6"
|
|
142
|
-
}
|
|
143
|
-
IGNOREFILE
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
before do
|
|
147
|
-
File.open(ignorefile_path, 'w') do |f|
|
|
148
|
-
f.write file_content
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
it 'does not raise an error and leaves the file intact' do
|
|
153
|
-
expect(File.read(ignorefile_path)).to eq(file_content)
|
|
154
|
-
expect { subject.call(message, '') }.not_to change { File.read(ignorefile_path) }
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
context 'when recording new deprecations' do
|
|
158
|
-
let(:line_number) { '456' }
|
|
159
|
-
|
|
160
|
-
before do
|
|
161
|
-
allow(Uncruft).to receive(:record_deprecations?).and_return(true)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it 'does not raise an error and leaves the file intact' do
|
|
165
|
-
expect(File.read(ignorefile_path)).to eq(file_content)
|
|
166
|
-
expect { subject.call(message, '') }.not_to raise_error
|
|
167
|
-
expect(File.read(ignorefile_path)).to include('Warning: BAD called from chicken/nuggets.rb')
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uncruft::Railtie do
|
|
4
|
-
let(:app) { Rails.application }
|
|
5
|
-
let(:initializers) { app.initializers.tsort_each.select { |i| i.name.to_s.include?('deprecation') } }
|
|
6
|
-
|
|
7
|
-
it 'injects the default deprecation handler' do
|
|
8
|
-
expect { initializers.map { |i| i.run(app) } }.to change { Rails.application.config.active_support.deprecation }
|
|
9
|
-
.from(nil).to(a_collection_containing_exactly(an_instance_of(Uncruft::DeprecationHandler)))
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'when the configured behavior is :stderr' do
|
|
13
|
-
before do
|
|
14
|
-
Rails.application.config.active_support.deprecation = :stderr
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'injects the default deprecation handler' do
|
|
18
|
-
expect { initializers.map { |i| i.run(app) } }.to change { Rails.application.config.active_support.deprecation }
|
|
19
|
-
.from(:stderr).to(a_collection_containing_exactly(an_instance_of(Uncruft::DeprecationHandler)))
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'when a custom deprecation behavior is already configured' do
|
|
24
|
-
before do
|
|
25
|
-
Rails.application.config.active_support.deprecation = :notify
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'injects the default deprecation handler' do
|
|
29
|
-
expect { initializers.map { |i| i.run(app) } }.to change { Rails.application.config.active_support.deprecation }
|
|
30
|
-
.from(:notify).to(a_collection_containing_exactly(:notify, an_instance_of(Uncruft::DeprecationHandler)))
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uncruft::Warning do
|
|
4
|
-
before do
|
|
5
|
-
stub_const('Warning', Kernel) unless defined?(Warning)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "doesn't block generic warnings" do
|
|
9
|
-
expect(ActiveSupport::Deprecation).not_to receive(:warn)
|
|
10
|
-
warn('oh no, you should worry')
|
|
11
|
-
Kernel.warn('oh no, you should worry')
|
|
12
|
-
Warning.warn('oh no, you should worry')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "accepts kwargs from Kernel.warn" do
|
|
16
|
-
warn('oh no, you should worry', uplevel: 1)
|
|
17
|
-
Kernel.warn('oh no, you should worry', uplevel: 1)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context 'when warning includes the word "deprecation" or "deprecated"' do
|
|
21
|
-
it 'treats it as a deprecation warning' do
|
|
22
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).and_return('banana').exactly(6).times
|
|
23
|
-
expect(warn('[dEpReCaTiOn] oh no, you should worry')).to eq 'banana'
|
|
24
|
-
expect(Kernel.warn('[dEpReCaTiOn] oh no, you should worry')).to eq 'banana'
|
|
25
|
-
expect(Warning.warn('[dEpReCaTiOn] oh no, you should worry')).to eq 'banana'
|
|
26
|
-
expect(warn('oh no, this is DePrEcAtEd, so you should worry')).to eq 'banana'
|
|
27
|
-
expect(Kernel.warn('oh no, this is DePrEcAtEd, so you should worry')).to eq 'banana'
|
|
28
|
-
expect(Warning.warn('oh no, this is DePrEcAtEd, so you should worry')).to eq 'banana'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'and when warning includes caller info' do
|
|
32
|
-
it 'strips out the path so that ActiveSupport::Deprecation can append a new one' do
|
|
33
|
-
path = caller_locations(0..0).first.path
|
|
34
|
-
|
|
35
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).with('foo is deprecated!').and_return('hurray')
|
|
36
|
-
expect(warn("#{path}: foo is deprecated!")).to eq('hurray')
|
|
37
|
-
|
|
38
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).with('[DEPRECATION] bar is no more.').and_return('huzzah')
|
|
39
|
-
expect(Kernel.warn("[DEPRECATION] bar is no more. #{path}:#{caller_locations(0..0).first.lineno}")).to eq('huzzah')
|
|
40
|
-
|
|
41
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).with('Deprecation detected: banana --').and_return('we do our best...')
|
|
42
|
-
expect(Warning.warn("Deprecation detected: banana -- #{caller(0..0).first}")).to eq('we do our best...')
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
data/spec/uncruft_spec.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Uncruft do
|
|
4
|
-
describe '.record_deprecations?' do
|
|
5
|
-
it 'handles common truthy and falsy values' do
|
|
6
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('1')
|
|
7
|
-
expect(described_class.record_deprecations?).to eq true
|
|
8
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('t')
|
|
9
|
-
expect(described_class.record_deprecations?).to eq true
|
|
10
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('T')
|
|
11
|
-
expect(described_class.record_deprecations?).to eq true
|
|
12
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('true')
|
|
13
|
-
expect(described_class.record_deprecations?).to eq true
|
|
14
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('TRUE')
|
|
15
|
-
expect(described_class.record_deprecations?).to eq true
|
|
16
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('0')
|
|
17
|
-
expect(described_class.record_deprecations?).to eq false
|
|
18
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('f')
|
|
19
|
-
expect(described_class.record_deprecations?).to eq false
|
|
20
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('F')
|
|
21
|
-
expect(described_class.record_deprecations?).to eq false
|
|
22
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('false')
|
|
23
|
-
expect(described_class.record_deprecations?).to eq false
|
|
24
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('FALSE')
|
|
25
|
-
expect(described_class.record_deprecations?).to eq false
|
|
26
|
-
allow(ENV).to receive(:[]).with('RECORD_DEPRECATIONS').and_return('')
|
|
27
|
-
expect(described_class.record_deprecations?).to be_nil
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe '.ignorefile_path' do
|
|
32
|
-
it 'uses rails root' do
|
|
33
|
-
expect(described_class.ignorefile_path).to eq(Rails.root.join('config', 'deprecations.ignore'))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'when env var is set' do
|
|
37
|
-
before do
|
|
38
|
-
allow(ENV).to receive(:[]).with('UNCRUFT_IGNOREFILE_PATH').and_return('/path/to/file.txt')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'uses env var' do
|
|
42
|
-
expect(described_class.ignorefile_path).to eq('/path/to/file.txt')
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|