Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a .ruby-version #101

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
- gemfiles/activesupport_7.0.gemfile
- gemfiles/activesupport_7.1.gemfile
- gemfiles/activesupport_edge.gemfile
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
ruby: ["3.0", "3.1", "3.2", "3.3"]
exclude:
- gemfile: gemfiles/activesupport_edge.gemfile
ruby: "2.7"
- gemfile: gemfiles/activesupport_edge.gemfile
ruby: "3.0"
env:
Expand Down Expand Up @@ -47,7 +45,6 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true

- name: RuboCop
Expand Down
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: 2.6
SuggestExtensions: false
Exclude:
- gemfiles/vendor/**/*
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
36 changes: 21 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ GEM
ruby2_keywords
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
minitest (5.20.0)
mutex_m (0.2.0)
parallel (1.21.0)
parser (3.1.1.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.1)
rexml (3.2.5)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
Expand All @@ -49,24 +53,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.25.1)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.15.1, < 2.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
rubocop-shopify (2.5.0)
rubocop (~> 1.25)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-shopify (2.15.1)
rubocop (~> 1.51)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
unicode-display_width (2.5.0)

PLATFORMS
ruby
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ This gem provides 4 behaviors, the default one being `DeprecationToolkit::Behavi
DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
```

You can also create your own behavior class and perform the logic you want. Your behavior needs to respond to `.trigger`.
You can also create your own behavior object and perform the logic you want. Your behavior needs to respond to `trigger`.

```ruby
class StatsdBehavior
def self.trigger(test, deprecations, recorded_deprecations)
def trigger(test, deprecations, recorded_deprecations)
# Could send some statsd event for example
end
end

DeprecationToolkit::Configuration.behavior = StatsdBehavior
DeprecationToolkit::Configuration.behavior = StatsdBehavior.new
```

#### DeprecationToolkit::Behaviors::CIRecordHelper
Expand All @@ -75,7 +75,7 @@ This is a special type of behaviour meant to help you record deprecations if you
Imagine if you have thousands of tests and need to record deprecations for each on your machine, this is going to take ages.
Recording deprecations on CI with the regular `Record` behavior isn't possible because of the way CI parallelize test in multiple container (Multiple tests from the same file runs in parallel in diferrent machines, the deprecation files that get created are then splitted. Regrouping them is a nightmare.)

This behaviour will output a JSON representation of your deprecations. Your CI should have a way to download the log generated from the test run. Download it on your locale machine. Finally run the rake task `FILEPATH=<path_to_downloaded_log> deprecation_toolkit:record_from_ci_output`.
This behavior will output a JSON representation of your deprecations. Your CI should have a way to download the log generated from the test run. Download it on your locale machine. Finally run the rake task `FILEPATH=<path_to_downloaded_log> deprecation_toolkit:record_from_ci_output`.
This task will parse your CI log and grab the output generated by the DeprecationToolkit and will finally convert everything back to YML files.

### 🔨 `#DeprecationToolkit::Configuration#allowed_deprecations`
Expand Down
2 changes: 1 addition & 1 deletion deprecation_toolkit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.metadata["allowed_push_host"] = "https://rubygems.org"

spec.required_ruby_version = ">= 2.7"
spec.required_ruby_version = ">= 3.0.0"

spec.files = %x(git ls-files -z).split("\x0").reject do |f|
f.match(%r{^(test|spec|\.github|gemfiles)/})
Expand Down
5 changes: 3 additions & 2 deletions lib/deprecation_toolkit/behaviors/ci_record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

module DeprecationToolkit
module Behaviors
class CIRecordHelper
module CIRecordHelper
extend self
extend ReadWriteHelper

HEADER = "[DeprecationToolkit]"

def self.trigger(test, current_deprecations, _recorded_deprecations)
def trigger(test, current_deprecations, _recorded_deprecations)
filename = recorded_deprecations_path(test)

to_output = {
Expand Down
6 changes: 4 additions & 2 deletions lib/deprecation_toolkit/behaviors/disabled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module DeprecationToolkit
module Behaviors
class Disabled
def self.trigger(*)
module Disabled
extend self

def trigger(*)
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/deprecation_toolkit/behaviors/raise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module DeprecationToolkit
module Behaviors
class Raise
def self.trigger(_test, current_deprecations, recorded_deprecations)
module Raise
extend self

def trigger(_test, current_deprecations, recorded_deprecations)
error_class = if current_deprecations.size > recorded_deprecations.size
DeprecationIntroduced
elsif current_deprecations.size < recorded_deprecations.size
Expand Down
5 changes: 3 additions & 2 deletions lib/deprecation_toolkit/behaviors/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module DeprecationToolkit
module Behaviors
class Record
module Record
extend self
extend ReadWriteHelper

def self.trigger(test, collector, _)
def trigger(test, collector, _)
deprecation_file = recorded_deprecations_path(test)

write(deprecation_file, test_name(test) => collector.deprecations_without_stacktrace)
Expand Down
6 changes: 1 addition & 5 deletions lib/deprecation_toolkit/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ def flaky?
private

def active_support_deprecation_sub_params
if ActiveSupport.gem_version.to_s < "5.0"
[/\W\s\(called from .*\)$/, ""]
else
[/ \(called from .*\)$/, ""]
end
[/ \(called from .*\)$/, ""]
end

def gem_deprecate_sub_params
Expand Down
6 changes: 4 additions & 2 deletions lib/deprecation_toolkit/deprecation_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

module DeprecationToolkit
class DeprecationSubscriber < ActiveSupport::Subscriber
def self.already_attached?
notifier != nil
class << self
def already_attached?
notifier != nil
end
end

def deprecation(event)
Expand Down
4 changes: 3 additions & 1 deletion lib/deprecation_toolkit/test_triggerer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module DeprecationToolkit
module TestTriggerer
def self.trigger_deprecation_toolkit_behavior(test)
extend self

def trigger_deprecation_toolkit_behavior(test)
current_deprecations = DeprecationToolkit::Collector.new(DeprecationToolkit::Collector.deprecations)
recorded_deprecations = DeprecationToolkit::Collector.load(test)
if !recorded_deprecations.flaky? && current_deprecations != recorded_deprecations
Expand Down
2 changes: 1 addition & 1 deletion spec/deprecation_toolkit/behaviors/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def expect_deprecations_recorded(*deprecation_triggered, example)
yield

recorded = YAML.load_file(
"#{@deprecation_path}/deprecation_toolkit/behaviors/record.yml"
"#{@deprecation_path}/deprecation_toolkit/behaviors/record.yml",
).fetch("test_" + example.full_description.underscore.squish.tr(" ", "_"))
triggered = deprecation_triggered.map { |msg| "DEPRECATION WARNING: #{msg}" }

Expand Down
6 changes: 4 additions & 2 deletions test/deprecation_toolkit/behaviors/ci_record_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class CIRecordHelperTest < ActiveSupport::TestCase
MyTest = Class.new(::Minitest::Test) do
include TestDeprecator

def self.name
"MyTest"
class << self
def name
"MyTest"
end
end

def test_generate_deprecation
Expand Down
1 change: 0 additions & 1 deletion test/deprecation_toolkit/behaviors/record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def example; end

assert_match(/.*#example is deprecated; use new_example instead\./, recorded_deprecation)
refute_match(/called from/, recorded_deprecation)

ensure
Configuration.warnings_treated_as_deprecation = previous_warnings_treated_as_deprecation
end
Expand Down
8 changes: 6 additions & 2 deletions test/support/fake_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# This is needed so that when we run the tests in this project, and the plugin is initialized by Minitest, we don't
# cause a deprecation warning by calling `ActiveSupport::Deprecation.behavior` and `.behavior=`.
module Rails
def self.application
extend self

def application
Application
end

module Application
def self.deprecators
extend self

def deprecators
@deprecators ||= DeprecatorSet.new
end
end
Expand Down
14 changes: 8 additions & 6 deletions test/support/test_deprecator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

module TestDeprecator
def self.deprecator
@deprecator ||= ActiveSupport::Deprecation.new("next version", "test deprecator").tap do |deprecator|
deprecator.behavior = :notify
# `ActiveSupport::Subscriber.attach_to` can only be called once (or there will be duplicate deprecations) and with
# this singleton method we can ensure that.
DeprecationToolkit::DeprecationSubscriber.attach_to("test deprecator")
class << self
def deprecator
@deprecator ||= ActiveSupport::Deprecation.new("next version", "test deprecator").tap do |deprecator|
deprecator.behavior = :notify
# `ActiveSupport::Subscriber.attach_to` can only be called once (or there will be duplicate deprecations) and
# with this singleton method we can ensure that.
DeprecationToolkit::DeprecationSubscriber.attach_to("test deprecator")
end
end
end

Expand Down
Loading