deprecation_toolkit 1.3.0 → 1.4.0
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/.rspec +4 -0
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +16 -36
- data/.travis.yml +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +31 -17
- data/README.md +21 -0
- data/deprecation_toolkit.gemspec +1 -0
- data/gemfiles/spec/deprecations/deprecation_toolkit/behaviors/raise.yml +12 -0
- data/lib/deprecation_toolkit.rb +5 -1
- data/lib/deprecation_toolkit/behaviors/ci_record_helper.rb +1 -1
- data/lib/deprecation_toolkit/behaviors/raise.rb +22 -3
- data/lib/deprecation_toolkit/behaviors/record.rb +1 -1
- data/lib/deprecation_toolkit/configuration.rb +3 -2
- data/lib/deprecation_toolkit/minitest_hook.rb +1 -7
- data/lib/deprecation_toolkit/read_write_helper.rb +22 -6
- data/lib/deprecation_toolkit/rspec.rb +9 -0
- data/lib/deprecation_toolkit/rspec_plugin.rb +17 -0
- data/lib/deprecation_toolkit/test_triggerer.rb +17 -0
- data/lib/deprecation_toolkit/version.rb +1 -1
- data/spec/deprecation_toolkit/behaviors/disabled_spec.rb +23 -0
- data/spec/deprecation_toolkit/behaviors/raise_spec.rb +96 -0
- data/spec/deprecation_toolkit/behaviors/record_spec.rb +71 -0
- data/spec/deprecations/deprecation_toolkit/behaviors/raise.yml +12 -0
- data/spec/rspec/plugin_env_options_spec.rb +13 -0
- data/spec/rspec/plugin_spec.rb +18 -0
- data/spec/spec_helper.rb +19 -0
- metadata +28 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d2f08916abc502412bc2c68826947592e55e90a5eee9cce948e57145a9e3db4
|
|
4
|
+
data.tar.gz: d96b9c8941b6f769f2218e6695e7b1d99fcde3b4cb40fac5bace9d6af81706ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ba98635a5fcf3b30868ebeb4d7b52256c8444b2ef2681860308be56d506a6849e1c27d98cd2c9b2322490ec25f2416a09eb989be19a0c3bb819511cf491cf84
|
|
7
|
+
data.tar.gz: 2bda4d027138410c2752fb9217bd2a01bebf3c5f0420d4a0a571f7172ee8965483eebc76257b3d8df50e1f4f09d9c71fc69c1586a26491942970102f8419ec87
|
data/.rspec
ADDED
|
@@ -4,6 +4,9 @@ AllCops:
|
|
|
4
4
|
DisabledByDefault: true
|
|
5
5
|
StyleGuideBaseURL: https://shopify.github.io/ruby-style-guide/
|
|
6
6
|
|
|
7
|
+
Lint/AssignmentInCondition:
|
|
8
|
+
Enabled: true
|
|
9
|
+
|
|
7
10
|
Layout/AccessModifierIndentation:
|
|
8
11
|
EnforcedStyle: indent
|
|
9
12
|
SupportedStyles:
|
|
@@ -329,18 +332,6 @@ Style/NumericLiteralPrefix:
|
|
|
329
332
|
Style/ParenthesesAroundCondition:
|
|
330
333
|
AllowSafeAssignment: true
|
|
331
334
|
|
|
332
|
-
Style/PercentLiteralDelimiters:
|
|
333
|
-
PreferredDelimiters:
|
|
334
|
-
'%': '()'
|
|
335
|
-
'%i': '()'
|
|
336
|
-
'%q': '()'
|
|
337
|
-
'%Q': '()'
|
|
338
|
-
'%r': '{}'
|
|
339
|
-
'%s': '()'
|
|
340
|
-
'%w': '()'
|
|
341
|
-
'%W': '()'
|
|
342
|
-
'%x': '()'
|
|
343
|
-
|
|
344
335
|
Style/PercentQLiterals:
|
|
345
336
|
EnforcedStyle: lower_case_q
|
|
346
337
|
SupportedStyles:
|
|
@@ -516,14 +507,6 @@ Naming/VariableName:
|
|
|
516
507
|
Style/WhileUntilModifier:
|
|
517
508
|
Enabled: true
|
|
518
509
|
|
|
519
|
-
Style/WordArray:
|
|
520
|
-
EnforcedStyle: percent
|
|
521
|
-
SupportedStyles:
|
|
522
|
-
- percent
|
|
523
|
-
- brackets
|
|
524
|
-
MinSize: 0
|
|
525
|
-
WordRegex: !ruby/regexp /\A[\p{Word}\n\t]+\z/
|
|
526
|
-
|
|
527
510
|
Metrics/BlockNesting:
|
|
528
511
|
Max: 3
|
|
529
512
|
|
|
@@ -754,7 +737,7 @@ Style/EvenOdd:
|
|
|
754
737
|
Layout/InitialIndentation:
|
|
755
738
|
Enabled: true
|
|
756
739
|
|
|
757
|
-
|
|
740
|
+
Lint/FlipFlop:
|
|
758
741
|
Enabled: true
|
|
759
742
|
|
|
760
743
|
Style/IfInsideElse:
|
|
@@ -787,9 +770,6 @@ Style/MethodMissingSuper:
|
|
|
787
770
|
Style/MissingRespondToMissing:
|
|
788
771
|
Enabled: true
|
|
789
772
|
|
|
790
|
-
Style/MultilineBlockChain:
|
|
791
|
-
Enabled: true
|
|
792
|
-
|
|
793
773
|
Layout/MultilineBlockLayout:
|
|
794
774
|
Enabled: true
|
|
795
775
|
|
|
@@ -856,12 +836,18 @@ Style/RedundantParentheses:
|
|
|
856
836
|
Style/RedundantSelf:
|
|
857
837
|
Enabled: true
|
|
858
838
|
|
|
839
|
+
Style/RedundantSortBy:
|
|
840
|
+
Enabled: true
|
|
841
|
+
|
|
859
842
|
Layout/RescueEnsureAlignment:
|
|
860
843
|
Enabled: true
|
|
861
844
|
|
|
862
845
|
Style/RescueModifier:
|
|
863
846
|
Enabled: true
|
|
864
847
|
|
|
848
|
+
Style/Sample:
|
|
849
|
+
Enabled: true
|
|
850
|
+
|
|
865
851
|
Style/SelfAssignment:
|
|
866
852
|
Enabled: true
|
|
867
853
|
|
|
@@ -1107,30 +1093,18 @@ Performance/FixedSize:
|
|
|
1107
1093
|
Performance/FlatMap:
|
|
1108
1094
|
EnabledForFlattenWithoutParams: false
|
|
1109
1095
|
|
|
1110
|
-
Performance/LstripRstrip:
|
|
1111
|
-
Enabled: true
|
|
1112
|
-
|
|
1113
1096
|
Performance/RangeInclude:
|
|
1114
1097
|
Enabled: true
|
|
1115
1098
|
|
|
1116
|
-
Performance/RedundantBlockCall:
|
|
1117
|
-
Enabled: true
|
|
1118
|
-
|
|
1119
1099
|
Performance/RedundantMatch:
|
|
1120
1100
|
Enabled: true
|
|
1121
1101
|
|
|
1122
|
-
Performance/RedundantSortBy:
|
|
1123
|
-
Enabled: true
|
|
1124
|
-
|
|
1125
1102
|
Performance/RegexpMatch:
|
|
1126
1103
|
Enabled: true
|
|
1127
1104
|
|
|
1128
1105
|
Performance/ReverseEach:
|
|
1129
1106
|
Enabled: true
|
|
1130
1107
|
|
|
1131
|
-
Performance/Sample:
|
|
1132
|
-
Enabled: true
|
|
1133
|
-
|
|
1134
1108
|
Performance/Size:
|
|
1135
1109
|
Enabled: true
|
|
1136
1110
|
|
|
@@ -1143,6 +1117,9 @@ Performance/StartWith:
|
|
|
1143
1117
|
Performance/StringReplacement:
|
|
1144
1118
|
Enabled: true
|
|
1145
1119
|
|
|
1120
|
+
Rails/ApplicationRecord:
|
|
1121
|
+
Enabled: true
|
|
1122
|
+
|
|
1146
1123
|
Rails/DelegateAllowBlank:
|
|
1147
1124
|
Enabled: true
|
|
1148
1125
|
|
|
@@ -1172,6 +1149,9 @@ Security/Open:
|
|
|
1172
1149
|
Lint/BigDecimalNew:
|
|
1173
1150
|
Enabled: true
|
|
1174
1151
|
|
|
1152
|
+
Style/Strip:
|
|
1153
|
+
Enabled: true
|
|
1154
|
+
|
|
1175
1155
|
Style/TrailingBodyOnClass:
|
|
1176
1156
|
Enabled: true
|
|
1177
1157
|
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## master (unreleased)
|
|
4
4
|
|
|
5
|
+
## 1.4.0 (2019-04-29)
|
|
6
|
+
* [#37](https://github.com/Shopify/deprecation_toolkit/pull/37): Add Rspec support. (@andrewmarkle)
|
|
7
|
+
|
|
5
8
|
## 1.3.0 (2019-02-28)
|
|
6
9
|
* [#38](https://github.com/Shopify/deprecation_toolkit/pull/38): Add a way to mark test as flaky. (@Edouard-chin)
|
|
7
10
|
* [#39](https://github.com/Shopify/deprecation_toolkit/pull/39): Introduced a way to help recording massive amount of deprecations. (@Edouard-chin)
|
data/Gemfile.lock
CHANGED
|
@@ -1,43 +1,56 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
deprecation_toolkit (1.
|
|
4
|
+
deprecation_toolkit (1.4.0)
|
|
5
5
|
activesupport (>= 4.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (5.2.
|
|
10
|
+
activesupport (5.2.3)
|
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
12
|
i18n (>= 0.7, < 2)
|
|
13
13
|
minitest (~> 5.1)
|
|
14
14
|
tzinfo (~> 1.1)
|
|
15
15
|
ast (2.4.0)
|
|
16
|
-
concurrent-ruby (1.1.
|
|
17
|
-
|
|
16
|
+
concurrent-ruby (1.1.5)
|
|
17
|
+
diff-lcs (1.3)
|
|
18
|
+
i18n (1.6.0)
|
|
18
19
|
concurrent-ruby (~> 1.0)
|
|
19
|
-
jaro_winkler (1.5.
|
|
20
|
+
jaro_winkler (1.5.2)
|
|
20
21
|
minitest (5.11.3)
|
|
21
|
-
parallel (1.
|
|
22
|
-
parser (2.
|
|
22
|
+
parallel (1.17.0)
|
|
23
|
+
parser (2.6.3.0)
|
|
23
24
|
ast (~> 2.4.0)
|
|
24
|
-
|
|
25
|
-
rainbow (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
psych (3.1.0)
|
|
26
|
+
rainbow (3.0.0)
|
|
27
|
+
rake (12.3.2)
|
|
28
|
+
rspec (3.8.0)
|
|
29
|
+
rspec-core (~> 3.8.0)
|
|
30
|
+
rspec-expectations (~> 3.8.0)
|
|
31
|
+
rspec-mocks (~> 3.8.0)
|
|
32
|
+
rspec-core (3.8.0)
|
|
33
|
+
rspec-support (~> 3.8.0)
|
|
34
|
+
rspec-expectations (3.8.2)
|
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
36
|
+
rspec-support (~> 3.8.0)
|
|
37
|
+
rspec-mocks (3.8.0)
|
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
39
|
+
rspec-support (~> 3.8.0)
|
|
40
|
+
rspec-support (3.8.0)
|
|
41
|
+
rubocop (0.67.2)
|
|
29
42
|
jaro_winkler (~> 1.5.1)
|
|
30
43
|
parallel (~> 1.10)
|
|
31
|
-
parser (>= 2.5)
|
|
32
|
-
|
|
44
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
45
|
+
psych (>= 3.1.0)
|
|
33
46
|
rainbow (>= 2.2.2, < 4.0)
|
|
34
47
|
ruby-progressbar (~> 1.7)
|
|
35
|
-
unicode-display_width (
|
|
36
|
-
ruby-progressbar (1.
|
|
48
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
|
49
|
+
ruby-progressbar (1.10.0)
|
|
37
50
|
thread_safe (0.3.6)
|
|
38
51
|
tzinfo (1.2.5)
|
|
39
52
|
thread_safe (~> 0.1)
|
|
40
|
-
unicode-display_width (1.
|
|
53
|
+
unicode-display_width (1.5.0)
|
|
41
54
|
|
|
42
55
|
PLATFORMS
|
|
43
56
|
ruby
|
|
@@ -47,6 +60,7 @@ DEPENDENCIES
|
|
|
47
60
|
deprecation_toolkit!
|
|
48
61
|
minitest (~> 5.0)
|
|
49
62
|
rake
|
|
63
|
+
rspec (~> 3.0)
|
|
50
64
|
rubocop
|
|
51
65
|
|
|
52
66
|
BUNDLED WITH
|
data/README.md
CHANGED
|
@@ -114,6 +114,27 @@ a message in the console.
|
|
|
114
114
|
Deprecation Toolkit allows you to configure which warnings should be treated as deprecations in order for you
|
|
115
115
|
to keep track of them as if they were regular deprecations.
|
|
116
116
|
|
|
117
|
+
|
|
118
|
+
## RSpec
|
|
119
|
+
|
|
120
|
+
By default Deprecation Toolkit uses Minitest as its test runner. To use Deprecation Toolkit with RSpec you'll have to configure it.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
DeprecationToolkit::Configuration.test_runner = :rspec
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Also make sure to require the before/after hooks in your `spec_helper.rb` or `rails_helper.rb`.
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
require "deprecation_toolkit/rspec"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
It's possible to record deprecations while running your specs by adding an ENV['DEPRECATION_BEHAVIOR'] variable to your test run. Run your specs with this ENV set to `"record-deprecations"`, `"record"` (or simply the `"r"` shortcut).
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
DEPRECATION_BEHAVIOR="record" bundle exec rspec path/to/file_spec.rb
|
|
136
|
+
```
|
|
137
|
+
|
|
117
138
|
## License
|
|
118
139
|
|
|
119
140
|
Deprecation Toolkit is licensed under the [MIT license](LICENSE.txt).
|
data/deprecation_toolkit.gemspec
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_removed_error_when_deprecations_are_removed:
|
|
3
|
+
- 'DEPRECATION WARNING: Foo'
|
|
4
|
+
- 'DEPRECATION WARNING: Bar'
|
|
5
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_removed_when_mismatched_and_less_than_expected:
|
|
6
|
+
- 'DEPRECATION WARNING: A'
|
|
7
|
+
- 'DEPRECATION WARNING: B'
|
|
8
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_mismatch_when_same_number_of_deprecations_are_triggered_with_mismatches:
|
|
9
|
+
- 'DEPRECATION WARNING: C'
|
|
10
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_does_not_raise_when_deprecations_are_triggered_but_were_already_recorded:
|
|
11
|
+
- 'DEPRECATION WARNING: Foo'
|
|
12
|
+
- 'DEPRECATION WARNING: Bar'
|
data/lib/deprecation_toolkit.rb
CHANGED
|
@@ -7,6 +7,7 @@ module DeprecationToolkit
|
|
|
7
7
|
autoload :Configuration, "deprecation_toolkit/configuration"
|
|
8
8
|
autoload :Collector, "deprecation_toolkit/collector"
|
|
9
9
|
autoload :ReadWriteHelper, "deprecation_toolkit/read_write_helper"
|
|
10
|
+
autoload :TestTriggerer, "deprecation_toolkit/test_triggerer"
|
|
10
11
|
|
|
11
12
|
module Behaviors
|
|
12
13
|
autoload :Disabled, "deprecation_toolkit/behaviors/disabled"
|
|
@@ -33,5 +34,8 @@ module DeprecationToolkit
|
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
unless defined?(RSpec)
|
|
38
|
+
require "deprecation_toolkit/minitest_hook"
|
|
39
|
+
end
|
|
40
|
+
|
|
37
41
|
require "deprecation_toolkit/warning"
|
|
@@ -21,10 +21,16 @@ module DeprecationToolkit
|
|
|
21
21
|
class DeprecationIntroduced < DeprecationException
|
|
22
22
|
def initialize(current_deprecations, recorded_deprecations)
|
|
23
23
|
introduced_deprecations = current_deprecations - recorded_deprecations
|
|
24
|
+
record_message =
|
|
25
|
+
if DeprecationToolkit::Configuration.test_runner == :rspec
|
|
26
|
+
"You can record deprecations by adding the `DEPRECATION_BEHAVIOR='record'` ENV when running your specs."
|
|
27
|
+
else
|
|
28
|
+
"You can record deprecations by adding the `--record-deprecations` flag when running your tests."
|
|
29
|
+
end
|
|
24
30
|
|
|
25
31
|
message = <<~EOM
|
|
26
32
|
You have introduced new deprecations in the codebase. Fix or record them in order to discard this error.
|
|
27
|
-
|
|
33
|
+
#{record_message}
|
|
28
34
|
|
|
29
35
|
#{introduced_deprecations.join("\n")}
|
|
30
36
|
EOM
|
|
@@ -37,10 +43,17 @@ module DeprecationToolkit
|
|
|
37
43
|
def initialize(current_deprecations, recorded_deprecations)
|
|
38
44
|
removed_deprecations = recorded_deprecations - current_deprecations
|
|
39
45
|
|
|
46
|
+
record_message =
|
|
47
|
+
if DeprecationToolkit::Configuration.test_runner == :rspec
|
|
48
|
+
"You can re-record deprecations by setting the `DEPRECATION_BEHAVIOR='record'` ENV when running your specs."
|
|
49
|
+
else
|
|
50
|
+
"You can re-record deprecations by adding the `--record-deprecations` flag when running your tests."
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
message = <<~EOM
|
|
41
54
|
You have removed deprecations from the codebase. Thanks for being an awesome person.
|
|
42
55
|
The recorded deprecations needs to be updated to reflect your changes.
|
|
43
|
-
|
|
56
|
+
#{record_message}
|
|
44
57
|
|
|
45
58
|
#{removed_deprecations.join("\n")}
|
|
46
59
|
EOM
|
|
@@ -51,11 +64,17 @@ module DeprecationToolkit
|
|
|
51
64
|
|
|
52
65
|
class DeprecationMismatch < DeprecationException
|
|
53
66
|
def initialize(current_deprecations, recorded_deprecations)
|
|
67
|
+
record_message =
|
|
68
|
+
if DeprecationToolkit::Configuration.test_runner == :rspec
|
|
69
|
+
"You can re-record deprecations by adding the `DEPRECATION_BEHAVIOR='record'` ENV when running your specs."
|
|
70
|
+
else
|
|
71
|
+
"You can re-record deprecations by adding the `--record-deprecations` flag when running your tests."
|
|
72
|
+
end
|
|
54
73
|
message = <<~EOM
|
|
55
74
|
The recorded deprecations for this test doesn't match the one that got triggered.
|
|
56
75
|
Fix or record the new deprecations to discard this error.
|
|
57
76
|
|
|
58
|
-
|
|
77
|
+
#{record_message}
|
|
59
78
|
|
|
60
79
|
===== Expected
|
|
61
80
|
#{recorded_deprecations.deprecations.join("\n")}
|
|
@@ -8,7 +8,7 @@ module DeprecationToolkit
|
|
|
8
8
|
def self.trigger(test, collector, _)
|
|
9
9
|
deprecation_file = recorded_deprecations_path(test)
|
|
10
10
|
|
|
11
|
-
write(deprecation_file, test
|
|
11
|
+
write(deprecation_file, test_name(test) => collector.deprecations_without_stacktrace)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -6,10 +6,11 @@ module DeprecationToolkit
|
|
|
6
6
|
class Configuration
|
|
7
7
|
include ActiveSupport::Configurable
|
|
8
8
|
|
|
9
|
-
config_accessor(:behavior) { Behaviors::Raise }
|
|
10
9
|
config_accessor(:allowed_deprecations) { [] }
|
|
11
|
-
config_accessor(:deprecation_path) { "test/deprecations" }
|
|
12
10
|
config_accessor(:attach_to) { [:rails] }
|
|
11
|
+
config_accessor(:behavior) { Behaviors::Raise }
|
|
12
|
+
config_accessor(:deprecation_path) { "test/deprecations" }
|
|
13
|
+
config_accessor(:test_runner) { :minitest }
|
|
13
14
|
config_accessor(:warnings_treated_as_deprecation) { [] }
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -5,13 +5,7 @@ require "minitest"
|
|
|
5
5
|
module DeprecationToolkit
|
|
6
6
|
module Minitest
|
|
7
7
|
def trigger_deprecation_toolkit_behavior
|
|
8
|
-
|
|
9
|
-
recorded_deprecations = Collector.load(self)
|
|
10
|
-
if !recorded_deprecations.flaky? && current_deprecations != recorded_deprecations
|
|
11
|
-
Configuration.behavior.trigger(self, current_deprecations, recorded_deprecations)
|
|
12
|
-
end
|
|
13
|
-
ensure
|
|
14
|
-
Collector.reset!
|
|
8
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(self)
|
|
15
9
|
end
|
|
16
10
|
end
|
|
17
11
|
end
|
|
@@ -8,7 +8,7 @@ module DeprecationToolkit
|
|
|
8
8
|
module ReadWriteHelper
|
|
9
9
|
def read(test)
|
|
10
10
|
deprecation_file = Bundler.root.join(recorded_deprecations_path(test))
|
|
11
|
-
YAML.load(deprecation_file.read).fetch(test
|
|
11
|
+
YAML.load(deprecation_file.read).fetch(test_name(test), [])
|
|
12
12
|
rescue Errno::ENOENT
|
|
13
13
|
[]
|
|
14
14
|
end
|
|
@@ -17,11 +17,12 @@ module DeprecationToolkit
|
|
|
17
17
|
create_deprecation_file(deprecation_file) unless deprecation_file.exist?
|
|
18
18
|
|
|
19
19
|
content = YAML.load_file(deprecation_file)
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
deprecations_to_record.each do |test, deprecations|
|
|
21
22
|
if deprecations.any?
|
|
22
|
-
content[
|
|
23
|
+
content[test] = deprecations
|
|
23
24
|
else
|
|
24
|
-
content.delete(
|
|
25
|
+
content.delete(test)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -46,13 +47,28 @@ module DeprecationToolkit
|
|
|
46
47
|
Configuration.deprecation_path
|
|
47
48
|
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
path =
|
|
51
|
+
if DeprecationToolkit::Configuration.test_runner == :rspec
|
|
52
|
+
test.example_group.file_path.sub(%r{^./spec/}, "").sub(/_spec.rb$/, "")
|
|
53
|
+
else
|
|
54
|
+
test.class.name.underscore
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
Pathname(deprecation_folder).join("#{path}.yml")
|
|
50
58
|
end
|
|
51
59
|
|
|
52
60
|
def test_location(test)
|
|
53
|
-
test.method(test
|
|
61
|
+
test.method(test_name(test)).source_location[0]
|
|
54
62
|
rescue NameError
|
|
55
63
|
"unknown"
|
|
56
64
|
end
|
|
65
|
+
|
|
66
|
+
def test_name(test)
|
|
67
|
+
if DeprecationToolkit::Configuration.test_runner == :rspec
|
|
68
|
+
"test_" + test.full_description.underscore.squish.tr(" ", "_")
|
|
69
|
+
else
|
|
70
|
+
test.name
|
|
71
|
+
end
|
|
72
|
+
end
|
|
57
73
|
end
|
|
58
74
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DeprecationToolkit
|
|
4
|
+
module RSpecPlugin
|
|
5
|
+
RSpec.configure do |config|
|
|
6
|
+
config.before(:suite) do
|
|
7
|
+
case ENV['DEPRECATION_BEHAVIOR']
|
|
8
|
+
when "r", "record", "record-deprecations"
|
|
9
|
+
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
DeprecationToolkit.add_notify_behavior
|
|
13
|
+
DeprecationToolkit.attach_subscriber
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DeprecationToolkit
|
|
4
|
+
module TestTriggerer
|
|
5
|
+
def self.trigger_deprecation_toolkit_behavior(test)
|
|
6
|
+
current_deprecations = DeprecationToolkit::Collector.new(DeprecationToolkit::Collector.deprecations)
|
|
7
|
+
recorded_deprecations = DeprecationToolkit::Collector.load(test)
|
|
8
|
+
if !recorded_deprecations.flaky? && current_deprecations != recorded_deprecations
|
|
9
|
+
DeprecationToolkit::Configuration.behavior.trigger(
|
|
10
|
+
test, current_deprecations, recorded_deprecations
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
ensure
|
|
14
|
+
DeprecationToolkit::Collector.reset!
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe(DeprecationToolkit::Behaviors::Raise) do
|
|
6
|
+
before do
|
|
7
|
+
@previous_configuration = DeprecationToolkit::Configuration.behavior
|
|
8
|
+
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Disabled
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after do
|
|
12
|
+
DeprecationToolkit::Configuration.behavior = @previous_configuration
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it '.trigger noop any deprecations' do |example|
|
|
16
|
+
expect do
|
|
17
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
18
|
+
ActiveSupport::Deprecation.warn("Bar")
|
|
19
|
+
|
|
20
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
21
|
+
end.not_to(raise_error)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe(DeprecationToolkit::Behaviors::Raise) do
|
|
6
|
+
before do
|
|
7
|
+
@previous_configuration = DeprecationToolkit::Configuration.behavior
|
|
8
|
+
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Raise
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after do
|
|
12
|
+
DeprecationToolkit::Configuration.behavior = @previous_configuration
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it ".trigger raises an DeprecationIntroduced error when deprecations are introduced" do |example|
|
|
16
|
+
expect do
|
|
17
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
18
|
+
ActiveSupport::Deprecation.warn("Bar")
|
|
19
|
+
|
|
20
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
21
|
+
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationIntroduced))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it ".trigger raises a DeprecationRemoved error when deprecations are removed" do |example|
|
|
25
|
+
expect do
|
|
26
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
27
|
+
|
|
28
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
29
|
+
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationRemoved))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it '.trigger raises a DeprecationRemoved when mismatched and less than expected' do |example|
|
|
33
|
+
expect do
|
|
34
|
+
ActiveSupport::Deprecation.warn("C")
|
|
35
|
+
|
|
36
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
37
|
+
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationRemoved))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it '.trigger raises a DeprecationMismatch when same number of deprecations are triggered with mismatches' do |example|
|
|
41
|
+
expect do
|
|
42
|
+
ActiveSupport::Deprecation.warn("A")
|
|
43
|
+
|
|
44
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
45
|
+
end.to(raise_error(DeprecationToolkit::Behaviors::DeprecationMismatch))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it ".trigger does not raise when deprecations are triggered but were already recorded" do |example|
|
|
49
|
+
expect do
|
|
50
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
51
|
+
ActiveSupport::Deprecation.warn("Bar")
|
|
52
|
+
|
|
53
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
54
|
+
end.not_to(raise_error)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it ".trigger does not raise when deprecations are allowed with Regex" do |example|
|
|
58
|
+
@old_allowed_deprecations = DeprecationToolkit::Configuration.allowed_deprecations
|
|
59
|
+
DeprecationToolkit::Configuration.allowed_deprecations = [/John Doe/]
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
ActiveSupport::Deprecation.warn("John Doe")
|
|
63
|
+
expect do
|
|
64
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
65
|
+
end.not_to(raise_error)
|
|
66
|
+
ensure
|
|
67
|
+
DeprecationToolkit::Configuration.allowed_deprecations = @old_allowed_deprecations
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it ".trigger does not raise when deprecations are allowed with Procs" do |example|
|
|
72
|
+
class_eval <<-RUBY, 'my_file.rb', 1337
|
|
73
|
+
def deprecation_caller
|
|
74
|
+
deprecation_callee
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def deprecation_callee
|
|
78
|
+
ActiveSupport::Deprecation.warn("John Doe")
|
|
79
|
+
end
|
|
80
|
+
RUBY
|
|
81
|
+
|
|
82
|
+
old_allowed_deprecations = DeprecationToolkit::Configuration.allowed_deprecations
|
|
83
|
+
DeprecationToolkit::Configuration.allowed_deprecations = [
|
|
84
|
+
->(_, stack) { stack.first.to_s =~ /my_file\.rb/ },
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
begin
|
|
88
|
+
deprecation_caller
|
|
89
|
+
expect do
|
|
90
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
91
|
+
end.not_to(raise_error)
|
|
92
|
+
ensure
|
|
93
|
+
DeprecationToolkit::Configuration.allowed_deprecations = old_allowed_deprecations
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
RSpec.describe(DeprecationToolkit::Behaviors::Record) do
|
|
7
|
+
before do
|
|
8
|
+
@previous_deprecation_path = DeprecationToolkit::Configuration.deprecation_path
|
|
9
|
+
@deprecation_path = Dir.mktmpdir
|
|
10
|
+
@previous_behavior = DeprecationToolkit::Configuration.behavior
|
|
11
|
+
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
|
|
12
|
+
DeprecationToolkit::Configuration.deprecation_path = @deprecation_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after do
|
|
16
|
+
DeprecationToolkit::Configuration.behavior = @previous_behavior
|
|
17
|
+
DeprecationToolkit::Configuration.deprecation_path = @previous_deprecation_path
|
|
18
|
+
FileUtils.rm_rf(@deprecation_path)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it '.trigger should record deprecations' do |example|
|
|
22
|
+
expect_deprecations_recorded("Foo", "Bar", example) do
|
|
23
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
24
|
+
ActiveSupport::Deprecation.warn("Bar")
|
|
25
|
+
|
|
26
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it ".trigger re-record an existing deprecation file" do |example|
|
|
31
|
+
expect_deprecations_recorded("Foo", "Bar", example) do
|
|
32
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
33
|
+
ActiveSupport::Deprecation.warn("Bar")
|
|
34
|
+
|
|
35
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
expect_deprecations_recorded("Foo", example) do
|
|
39
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
40
|
+
|
|
41
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it ".trigger removes the deprecation file when all deprecations were removed" do |example|
|
|
46
|
+
expect_deprecations_recorded("Foo", example) do
|
|
47
|
+
ActiveSupport::Deprecation.warn("Foo")
|
|
48
|
+
|
|
49
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
expect do
|
|
53
|
+
expect_deprecations_recorded("Foo", example) do
|
|
54
|
+
DeprecationToolkit::TestTriggerer.trigger_deprecation_toolkit_behavior(example)
|
|
55
|
+
end
|
|
56
|
+
end.to(raise_error(Errno::ENOENT))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def expect_deprecations_recorded(*deprecation_triggered, example)
|
|
62
|
+
yield
|
|
63
|
+
|
|
64
|
+
recorded = YAML.load_file(
|
|
65
|
+
"#{@deprecation_path}/deprecation_toolkit/behaviors/record.yml"
|
|
66
|
+
).fetch("test_" + example.full_description.underscore.squish.tr(" ", "_"))
|
|
67
|
+
triggered = deprecation_triggered.map { |msg| "DEPRECATION WARNING: #{msg}" }
|
|
68
|
+
|
|
69
|
+
expect(recorded).to(eq(triggered))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_removed_error_when_deprecations_are_removed:
|
|
3
|
+
- 'DEPRECATION WARNING: Foo'
|
|
4
|
+
- 'DEPRECATION WARNING: Bar'
|
|
5
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_removed_when_mismatched_and_less_than_expected:
|
|
6
|
+
- 'DEPRECATION WARNING: A'
|
|
7
|
+
- 'DEPRECATION WARNING: B'
|
|
8
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_raises_a_deprecation_mismatch_when_same_number_of_deprecations_are_triggered_with_mismatches:
|
|
9
|
+
- 'DEPRECATION WARNING: C'
|
|
10
|
+
test_deprecation_toolkit/behaviors/raise_.trigger_does_not_raise_when_deprecations_are_triggered_but_were_already_recorded:
|
|
11
|
+
- 'DEPRECATION WARNING: Foo'
|
|
12
|
+
- 'DEPRECATION WARNING: Bar'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This needs to be set before we require `spec_helper` to simulate setting an ENV when running a spec like:
|
|
4
|
+
# `DEPRECATION_BEHAVIOR="record" bundle exec rspec path/to/spec.rb`
|
|
5
|
+
ENV['DEPRECATION_BEHAVIOR'] = "record"
|
|
6
|
+
|
|
7
|
+
require 'spec_helper'
|
|
8
|
+
|
|
9
|
+
RSpec.describe("DeprecationToolkit::RSpecPlugin ENV options") do
|
|
10
|
+
it 'should set the behavior to `Record` when ENV variable is set' do
|
|
11
|
+
expect(DeprecationToolkit::Configuration.behavior).to(eq(DeprecationToolkit::Behaviors::Record))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe(DeprecationToolkit::RSpecPlugin) do
|
|
6
|
+
it "should add `notify` behavior to the deprecations behavior list" do
|
|
7
|
+
behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify]
|
|
8
|
+
|
|
9
|
+
expect(ActiveSupport::Deprecation.behavior).to(include(behavior))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "doesn't remove previous deprecation behaviors" do
|
|
13
|
+
behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence]
|
|
14
|
+
ActiveSupport::Deprecation.behavior = behavior
|
|
15
|
+
|
|
16
|
+
expect(ActiveSupport::Deprecation.behavior).to(include(behavior))
|
|
17
|
+
end
|
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
4
|
+
require "deprecation_toolkit"
|
|
5
|
+
require "deprecation_toolkit/rspec_plugin"
|
|
6
|
+
require "active_support/all"
|
|
7
|
+
|
|
8
|
+
DeprecationToolkit::Configuration.test_runner = :rspec
|
|
9
|
+
DeprecationToolkit::Configuration.deprecation_path = "spec/deprecations"
|
|
10
|
+
ActiveSupport::Deprecation.behavior = :silence
|
|
11
|
+
|
|
12
|
+
RSpec.configure do |config|
|
|
13
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
|
14
|
+
config.disable_monkey_patching!
|
|
15
|
+
|
|
16
|
+
config.expect_with(:rspec) do |c|
|
|
17
|
+
c.syntax = :expect
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deprecation_toolkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-04-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -66,6 +66,20 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '5.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
69
83
|
description:
|
|
70
84
|
email:
|
|
71
85
|
- rails@shopify.com
|
|
@@ -74,6 +88,7 @@ extensions: []
|
|
|
74
88
|
extra_rdoc_files: []
|
|
75
89
|
files:
|
|
76
90
|
- ".gitignore"
|
|
91
|
+
- ".rspec"
|
|
77
92
|
- ".rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml"
|
|
78
93
|
- ".rubocop.yml"
|
|
79
94
|
- ".travis.yml"
|
|
@@ -88,6 +103,7 @@ files:
|
|
|
88
103
|
- gemfiles/activesupport_5.0.gemfile
|
|
89
104
|
- gemfiles/activesupport_5.1.gemfile
|
|
90
105
|
- gemfiles/activesupport_5.2.gemfile
|
|
106
|
+
- gemfiles/spec/deprecations/deprecation_toolkit/behaviors/raise.yml
|
|
91
107
|
- gemfiles/test/deprecations
|
|
92
108
|
- lib/deprecation_toolkit.rb
|
|
93
109
|
- lib/deprecation_toolkit/behaviors/ci_record_helper.rb
|
|
@@ -99,11 +115,21 @@ files:
|
|
|
99
115
|
- lib/deprecation_toolkit/deprecation_subscriber.rb
|
|
100
116
|
- lib/deprecation_toolkit/minitest_hook.rb
|
|
101
117
|
- lib/deprecation_toolkit/read_write_helper.rb
|
|
118
|
+
- lib/deprecation_toolkit/rspec.rb
|
|
119
|
+
- lib/deprecation_toolkit/rspec_plugin.rb
|
|
120
|
+
- lib/deprecation_toolkit/test_triggerer.rb
|
|
102
121
|
- lib/deprecation_toolkit/version.rb
|
|
103
122
|
- lib/deprecation_toolkit/warning.rb
|
|
104
123
|
- lib/minitest/deprecation_toolkit_plugin.rb
|
|
105
124
|
- lib/tasks/ci_recorder.rake
|
|
106
125
|
- shipit.rubygems.yml
|
|
126
|
+
- spec/deprecation_toolkit/behaviors/disabled_spec.rb
|
|
127
|
+
- spec/deprecation_toolkit/behaviors/raise_spec.rb
|
|
128
|
+
- spec/deprecation_toolkit/behaviors/record_spec.rb
|
|
129
|
+
- spec/deprecations/deprecation_toolkit/behaviors/raise.yml
|
|
130
|
+
- spec/rspec/plugin_env_options_spec.rb
|
|
131
|
+
- spec/rspec/plugin_spec.rb
|
|
132
|
+
- spec/spec_helper.rb
|
|
107
133
|
homepage: https://github.com/shopify/deprecation_toolkit
|
|
108
134
|
licenses:
|
|
109
135
|
- MIT
|