deprecation_toolkit 2.0.3 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a215b859ad3948057d353332378a89f8ff22199296677f2ecab9f318d24a73b3
4
- data.tar.gz: 99a5d3368ab2a066a4118ba0330a913223214ba686c5779138cc685610eea4ae
3
+ metadata.gz: 4ed492475deec1821f75a8e79aa20ad0415abc84d55a1901e41bc178f8b3e7b5
4
+ data.tar.gz: 9420f08d816ea5c65331d91aad7cf942dcd3efe06fbf9eb78fd6f74f026528db
5
5
  SHA512:
6
- metadata.gz: a6b2c17228b8091e8d2260fb6aa001153b859fcc029412133552b6fb074cb547735bbd27e1194c36128f390658c4e8b82e76018244388a91a56528f6fad05256
7
- data.tar.gz: 4199799c0190b92530119d4ad093e359a6b076f35a1ceb039081bbdf6c0b26bd3731cd36fedb6f6025e3bc4bedd7fc38cd43c13e21652b7a3ac898a9a86c3d37
6
+ metadata.gz: 86fcf411a9243ceb75c551de88194a12606ededb0174ea3a0336fee7093f673702deb76c409e6ad642a02cef169991eb9a0f73a90a84a57448fbfcbb8d4e9583
7
+ data.tar.gz: bb1b607fd1bf0dba205be60a672ab9c6931c0eb66bc338a5f6b281992f6603e899d954201f04f174e20926b999191eb4663d4cc7a78f7d34ff2499d7e39b3f13
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ inherit_gem:
3
3
 
4
4
  AllCops:
5
5
  TargetRubyVersion: 2.6
6
+ SuggestExtensions: false
6
7
  Exclude:
7
8
  - gemfiles/vendor/**/*
8
9
 
data/CHANGELOG.md CHANGED
@@ -2,9 +2,19 @@
2
2
 
3
3
  ## main (unreleased)
4
4
 
5
+ ## 2.1.0 (2024-01-19)
6
+
7
+ * [#99](https://github.com/Shopify/deprecation_toolkit/pull/99): Fix `Warning.warn` hook to accept a category.
8
+ * [#95](https://github.com/Shopify/deprecation_toolkit/pull/95): Allow configuration of deprecation file paths and file names.
9
+
10
+ ## 2.0.4 (2023-11-20)
11
+
12
+ * [#90](https://github.com/Shopify/deprecation_toolkit/pull/90) & [#93](https://github.com/Shopify/deprecation_toolkit/pull/93): Stop using deprecated behavior from Active Support. (@etiennebarrie)
13
+ * [#91](https://github.com/Shopify/deprecation_toolkit/pull/91): Require necessary Active Support core extension. (@etiennebarrie)
14
+
5
15
  ## 2.0.3 (2023-02-10)
6
16
 
7
- * [#80](https://github.com/Shopify/deprecation_toolkit/pull/80): Filter out stack trace from Gem::Deprecate deprecation messages
17
+ * [#80](https://github.com/Shopify/deprecation_toolkit/pull/80): Filter out stack trace from Gem::Deprecate deprecation messages (@davidstosik)
8
18
 
9
19
  ## 2.0.2 (2023-02-08)
10
20
 
data/Gemfile.lock CHANGED
@@ -1,23 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deprecation_toolkit (2.0.3)
5
- activesupport (>= 5.2)
4
+ deprecation_toolkit (2.1.0)
5
+ activesupport (>= 7.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (7.0.4.2)
10
+ activesupport (7.1.2)
11
+ base64
12
+ bigdecimal
11
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
12
16
  i18n (>= 1.6, < 2)
13
17
  minitest (>= 5.1)
18
+ mutex_m
14
19
  tzinfo (~> 2.0)
15
20
  ast (2.4.2)
16
- concurrent-ruby (1.2.0)
21
+ base64 (0.2.0)
22
+ bigdecimal (3.1.4)
23
+ concurrent-ruby (1.2.2)
24
+ connection_pool (2.4.1)
17
25
  diff-lcs (1.5.0)
18
- i18n (1.12.0)
26
+ drb (2.2.0)
27
+ ruby2_keywords
28
+ i18n (1.14.1)
19
29
  concurrent-ruby (~> 1.0)
20
- minitest (5.15.0)
30
+ minitest (5.20.0)
31
+ mutex_m (0.2.0)
21
32
  parallel (1.21.0)
22
33
  parser (3.1.1.0)
23
34
  ast (~> 2.4.1)
@@ -52,6 +63,7 @@ GEM
52
63
  rubocop-shopify (2.5.0)
53
64
  rubocop (~> 1.25)
54
65
  ruby-progressbar (1.11.0)
66
+ ruby2_keywords (0.0.5)
55
67
  tzinfo (2.0.6)
56
68
  concurrent-ruby (~> 1.0)
57
69
  unicode-display_width (2.1.0)
data/README.md CHANGED
@@ -117,6 +117,31 @@ This setting accepts an array of regular expressions. To match on all warnings,
117
117
  DeprecationToolkit::Configuration.warnings_treated_as_deprecation = [//]
118
118
  ```
119
119
 
120
+ ### 🔨 `#DeprecationToolkit::Configuration#deprecation_file_path_format`
121
+
122
+ DeprecationToolkit allows you to choose the file path format for deprecation files.
123
+
124
+ For Minitest, it defaults to using class name so the following code would correspond to `#{deprecation_path}/deprecation_toolkit/behaviors/raise_test.yml`
125
+
126
+ ```ruby
127
+ module DeprecationToolkit
128
+ module Behaviors
129
+ class RaiseTest < ActiveSupport::TestCase
130
+ end
131
+ end
132
+ end
133
+ ```
134
+
135
+ For rspec if defaults to the file location with spec removed. `/spec/models/user_spec.rb` would correspond to `/models/user.yml`.
136
+
137
+ If you have a specific use case you can configure this with a custom format using a proc. The proc is called with an instance of the test.
138
+
139
+ ```ruby
140
+ Configuration.deprecation_file_path_format = -> (test) do
141
+ Kernel.const_source_location(test.class.name)[0].sub(%r{^./test/}, "").sub(/_test.rb$/, "")
142
+ end
143
+ ```
144
+
120
145
  ## RSpec
121
146
 
122
147
  By default Deprecation Toolkit uses Minitest as its test runner. To use Deprecation Toolkit with RSpec you'll have to configure it.
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = ">= 2.7"
24
24
 
25
25
  spec.files = %x(git ls-files -z).split("\x0").reject do |f|
26
- f.match(%r{^(test)/})
26
+ f.match(%r{^(test|spec|\.github|gemfiles)/})
27
27
  end
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency("activesupport", ">= 5.2")
30
+ spec.add_runtime_dependency("activesupport", ">= 7.0")
31
31
  end
@@ -12,5 +12,14 @@ module DeprecationToolkit
12
12
  config_accessor(:deprecation_path) { "test/deprecations" }
13
13
  config_accessor(:test_runner) { :minitest }
14
14
  config_accessor(:warnings_treated_as_deprecation) { [] }
15
+ config_accessor(:deprecation_file_path_format) do
16
+ proc do |test|
17
+ if DeprecationToolkit::Configuration.test_runner == :rspec
18
+ test.example_group.file_path.sub(%r{^./spec/}, "").sub(/_spec.rb$/, "")
19
+ else
20
+ test.class.name.underscore
21
+ end
22
+ end
23
+ end
15
24
  end
16
25
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/core_ext/string/inflections"
4
+ require "active_support/core_ext/string/filters"
4
5
  require "bundler"
5
6
  require "yaml"
6
7
 
@@ -47,12 +48,7 @@ module DeprecationToolkit
47
48
  Configuration.deprecation_path
48
49
  end
49
50
 
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
51
+ path = Configuration.deprecation_file_path_format.call(test)
56
52
 
57
53
  Pathname(deprecation_folder).join("#{path}.yml")
58
54
  end
@@ -2,16 +2,22 @@
2
2
 
3
3
  module DeprecationToolkit
4
4
  module RSpecPlugin
5
+ extend self
6
+
5
7
  RSpec.configure do |config|
6
8
  config.before(:suite) do
7
- case ENV["DEPRECATION_BEHAVIOR"]
8
- when "r", "record", "record-deprecations"
9
- DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
10
- end
9
+ RSpecPlugin.before_suite
10
+ end
11
+ end
11
12
 
12
- DeprecationToolkit.add_notify_behavior
13
- DeprecationToolkit.attach_subscriber
13
+ def before_suite
14
+ case ENV["DEPRECATION_BEHAVIOR"]
15
+ when "r", "record", "record-deprecations"
16
+ DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
14
17
  end
18
+
19
+ DeprecationToolkit.add_notify_behavior
20
+ DeprecationToolkit.attach_subscriber
15
21
  end
16
22
  end
17
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeprecationToolkit
4
- VERSION = "2.0.3"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -40,21 +40,29 @@ module DeprecationToolkit
40
40
  def deprecation_triggered?(str)
41
41
  DeprecationToolkit::Configuration.warnings_treated_as_deprecation.any? { |warning| warning =~ str }
42
42
  end
43
+
44
+ def deprecator
45
+ @deprecator ||= ActiveSupport::Deprecation.new("next", "DeprecationToolkit::Warning").tap do |deprecator|
46
+ deprecator.behavior = :notify
47
+ DeprecationSubscriber.attach_to(:deprecation_toolkit_warning)
48
+ end
49
+ end
43
50
  end
44
51
  end
45
52
 
46
53
  module DeprecationToolkit
47
54
  module WarningPatch
48
- def warn(str)
55
+ def warn(str, *)
49
56
  str = DeprecationToolkit::Warning.handle_multipart(str)
50
57
  return unless str
51
58
 
52
59
  if DeprecationToolkit::Warning.deprecation_triggered?(str)
53
- ActiveSupport::Deprecation.warn(str)
60
+ DeprecationToolkit::Warning.deprecator.warn(str)
54
61
  else
55
62
  super
56
63
  end
57
64
  end
65
+ ruby2_keywords :warn
58
66
  end
59
67
  end
60
68
  Warning.singleton_class.prepend(DeprecationToolkit::WarningPatch)
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: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-10 00:00:00.000000000 Z
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '7.0'
27
27
  description:
28
28
  email:
29
29
  - rails@shopify.com
@@ -31,8 +31,6 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - ".github/workflows/ci.yml"
35
- - ".github/workflows/cla.yml"
36
34
  - ".gitignore"
37
35
  - ".rspec"
38
36
  - ".rubocop.yml"
@@ -44,13 +42,6 @@ files:
44
42
  - RELEASE.md
45
43
  - Rakefile
46
44
  - deprecation_toolkit.gemspec
47
- - gemfiles/activesupport_5.2.gemfile
48
- - gemfiles/activesupport_6.0.gemfile
49
- - gemfiles/activesupport_6.1.gemfile
50
- - gemfiles/activesupport_7.0.gemfile
51
- - gemfiles/activesupport_edge.gemfile
52
- - gemfiles/spec/deprecations/deprecation_toolkit/behaviors/raise.yml
53
- - gemfiles/test/deprecations
54
45
  - lib/deprecation_toolkit.rb
55
46
  - lib/deprecation_toolkit/behaviors/ci_record_helper.rb
56
47
  - lib/deprecation_toolkit/behaviors/disabled.rb
@@ -69,13 +60,6 @@ files:
69
60
  - lib/minitest/deprecation_toolkit_plugin.rb
70
61
  - lib/tasks/ci_recorder.rake
71
62
  - shipit.rubygems.yml
72
- - spec/deprecation_toolkit/behaviors/disabled_spec.rb
73
- - spec/deprecation_toolkit/behaviors/raise_spec.rb
74
- - spec/deprecation_toolkit/behaviors/record_spec.rb
75
- - spec/deprecations/deprecation_toolkit/behaviors/raise.yml
76
- - spec/rspec/plugin_env_options_spec.rb
77
- - spec/rspec/plugin_spec.rb
78
- - spec/spec_helper.rb
79
63
  homepage: https://github.com/shopify/deprecation_toolkit
80
64
  licenses:
81
65
  - MIT
@@ -99,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
83
  - !ruby/object:Gem::Version
100
84
  version: '0'
101
85
  requirements: []
102
- rubygems_version: 3.3.3
86
+ rubygems_version: 3.5.4
103
87
  signing_key:
104
88
  specification_version: 4
105
89
  summary: Deprecation Toolkit around ActiveSupport::Deprecation
@@ -1,50 +0,0 @@
1
- name: CI
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- functionality:
7
- runs-on: ubuntu-latest
8
- name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }}
9
- strategy:
10
- matrix:
11
- gemfile: [gemfiles/activesupport_5.2.gemfile, gemfiles/activesupport_6.0.gemfile, gemfiles/activesupport_6.1.gemfile, gemfiles/activesupport_7.0.gemfile, gemfiles/activesupport_edge.gemfile]
12
- ruby: ["2.7", "3.0", "3.1", "3.2"]
13
- exclude:
14
- # Active Support requires Ruby >= 2.7 as of 7.0
15
- - gemfile: "gemfiles/activesupport_7.0.gemfile"
16
- ruby: "2.6"
17
- - gemfile: "gemfiles/activesupport_edge.gemfile"
18
- ruby: "2.6"
19
- env:
20
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
21
- steps:
22
-
23
- - name: Check out code
24
- uses: actions/checkout@v3
25
-
26
- - name: Set up Ruby ${{ matrix.ruby }}
27
- uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - name: Tests
33
- run: bundle exec rake test
34
-
35
- - name: Specs
36
- run: bundle exec rspec
37
- style:
38
- runs-on: ubuntu-latest
39
- name: Rubocop
40
- steps:
41
- - name: Check out code
42
- uses: actions/checkout@v3
43
-
44
- - uses: ruby/setup-ruby@v1
45
- with:
46
- ruby-version: "3.2"
47
- bundler-cache: true
48
-
49
- - name: RuboCop
50
- run: bundle exec rubocop
@@ -1,26 +0,0 @@
1
- name: Contributor License Agreement (CLA)
2
-
3
- on:
4
- pull_request_target:
5
- types: [opened, synchronize]
6
- issue_comment:
7
- types: [created]
8
-
9
- permissions:
10
- pull-requests: write # to set the label
11
- actions: write # to re-run the workflow when a comment is received
12
-
13
- jobs:
14
- cla:
15
- runs-on: ubuntu-latest
16
- if: |
17
- (github.event.issue.pull_request
18
- && !github.event.issue.pull_request.merged_at
19
- && contains(github.event.comment.body, 'signed')
20
- )
21
- || (github.event.pull_request && !github.event.pull_request.merged)
22
- steps:
23
- - uses: Shopify/shopify-cla-action@v1
24
- with:
25
- github-token: ${{ secrets.GITHUB_TOKEN }}
26
- cla-token: ${{ secrets.CLA_TOKEN }}
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- @activesupport_gem_requirement = "~> 5.2"
4
-
5
- eval_gemfile "../Gemfile"
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- @activesupport_gem_requirement = "~> 6.0"
4
-
5
- eval_gemfile "../Gemfile"
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- @activesupport_gem_requirement = "~> 6.1"
4
-
5
- eval_gemfile "../Gemfile"
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- @activesupport_gem_requirement = "~> 7.0"
4
-
5
- eval_gemfile "../Gemfile"
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- @activesupport_gem_requirement = { github: "rails/rails" }
4
-
5
- eval_gemfile "../Gemfile"
@@ -1,12 +0,0 @@
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'
@@ -1 +0,0 @@
1
- ../../test/deprecations
@@ -1,23 +0,0 @@
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
@@ -1,96 +0,0 @@
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
@@ -1,71 +0,0 @@
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
@@ -1,12 +0,0 @@
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'
@@ -1,13 +0,0 @@
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
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,19 +0,0 @@
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