uncruft 0.3.0 → 0.3.1

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: 1c93c7cc504ba0e5d3bf93b8ffbbfadee05e66c8084f3580fc93855490ed4ec3
4
- data.tar.gz: 6b1f3835bb69a640c757896730bb9cf284f212087f9f04339709e0186f921b92
3
+ metadata.gz: a2cab324dae5f8b3fc23c4f99785900af558ab66cee8a908222b3e7793482a35
4
+ data.tar.gz: 65ce169801afae62f4bd2b005b0ec901416c7f1372c2c5ca48a8ca3a9e9b79b0
5
5
  SHA512:
6
- metadata.gz: f6427a8d529e5b0f51f26c3fc8b88f06d3f9823a0d02eb0e3cfdf3c00419dab9c9f2c634adec618ba21c72f54cc9ddedd6b90c18aaad854ea7c0564c224dff52
7
- data.tar.gz: 67fba4c3a6ba79098cc141f597e7965917804306b41d5299cb4795600f191a3c5c8589506e4073d7be9ec6f045b75abe635338a75077ebc28b35b4848773d446
6
+ metadata.gz: 4d8f03d9ae4074f0097facfa7f20895ef17ec72082ba4f2a2fa49ddc8dfef688a7574f2fab60d134a42e60fa0ef841ce9201a9226da3e0dc9bd239737d260a88
7
+ data.tar.gz: 6f5857f50049b5016bb96d3e106de7c5a54818625c7922de2cb2b1971b857118af64bdf19a414694862b77d22b5a015c7f908ecc683899c8df5a4dc743ce14de
@@ -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
- elsif (absolute_path = absolute_path(message)).present?
46
- message.gsub(absolute_path, relative_path(absolute_path))
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{called from( .+ at)? (#{ENV['GEM_HOME']}/(.+/)*gems)})&.[](2)
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)
@@ -1,3 +1,3 @@
1
1
  module Uncruft
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  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.3.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: 2022-01-10 00:00:00.000000000 Z
12
+ date: 2023-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -112,14 +112,6 @@ 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/spec_helper.rb
117
- - spec/support/rails_root.rb
118
- - spec/uncruft/deprecatable_spec.rb
119
- - spec/uncruft/deprecation_handler_spec.rb
120
- - spec/uncruft/railtie_spec.rb
121
- - spec/uncruft/warning_spec.rb
122
- - spec/uncruft_spec.rb
123
115
  homepage: https://github.com/Betterment/uncruft
124
116
  licenses:
125
117
  - MIT
@@ -140,16 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
132
  - !ruby/object:Gem::Version
141
133
  version: '0'
142
134
  requirements: []
143
- rubygems_version: 3.1.6
135
+ rubygems_version: 3.3.5
144
136
  signing_key:
145
137
  specification_version: 4
146
138
  summary: A library to assist with Rails upgrades
147
- test_files:
148
- - spec/spec_helper.rb
149
- - spec/dummy/config/application.rb
150
- - spec/uncruft/railtie_spec.rb
151
- - spec/uncruft/warning_spec.rb
152
- - spec/uncruft/deprecatable_spec.rb
153
- - spec/uncruft/deprecation_handler_spec.rb
154
- - spec/support/rails_root.rb
155
- - 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/spec_helper.rb DELETED
@@ -1,17 +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
- RSpec.configure do |config|
9
- config.run_all_when_everything_filtered = true
10
- config.example_status_persistence_file_path = 'spec/examples.txt'
11
-
12
- config.around(:all) do |example|
13
- Time.use_zone(ActiveSupport::TimeZone.all.first) do
14
- example.run
15
- end
16
- end
17
- end
@@ -1,7 +0,0 @@
1
- module ::Rails
2
- class << self
3
- def root
4
- @root ||= Pathname.new(Dir.pwd).realpath.join('spec', 'dummy')
5
- end
6
- end
7
- end
@@ -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
- allow(ActiveSupport::Deprecation).to receive(:warn).with('foo is deprecated!').and_return('hurray')
36
- expect(warn("#{path}: foo is deprecated!")).to eq('hurray')
37
-
38
- allow(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
- allow(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