From 61b2f88d6d77dd06a93de25a1d8aeaabf2c0bb68 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Sun, 22 Sep 2024 22:46:34 +0300 Subject: [PATCH 1/6] Add `prism` to gemspec --- rubocop-thread_safety.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/rubocop-thread_safety.gemspec b/rubocop-thread_safety.gemspec index 6050be9..94f3aa6 100644 --- a/rubocop-thread_safety.gemspec +++ b/rubocop-thread_safety.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'appraisal' spec.add_development_dependency 'bundler', '>= 1.10', '< 3' + spec.add_development_dependency 'prism' spec.add_development_dependency 'pry' unless ENV['CI'] spec.add_development_dependency 'rake', '>= 10.0' spec.add_development_dependency 'rspec', '~> 3.0' From 3026b188b049fe9301432809cf28846f87490b67 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Sun, 22 Sep 2024 22:46:50 +0300 Subject: [PATCH 2/6] Fix failing on MRI 3.3 specs --- .../cop/thread_safety/mutable_class_instance_variable_spec.rb | 4 ++-- spec/spec_helper.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb b/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb index 5927aed..bc6346b 100644 --- a/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb +++ b/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb @@ -282,7 +282,7 @@ def some_method it_behaves_like 'mutable objects', %("\#{a}") end - context 'when the frozen_string_literal comment is true' do + context 'when the frozen_string_literal comment is true', unsupported_on: :prism do let(:prefix) { "# frozen_string_literal: true\n#{super()}" } it_behaves_like 'immutable objects', %("\#{a}") @@ -605,7 +605,7 @@ def assignment? it_behaves_like 'mutable objects', %("\#{a}") end - context 'when the frozen_string_literal comment is true' do + context 'when the frozen_string_literal comment is true', unsupported_on: :prism do let(:prefix) { "# frozen_string_literal: true\n#{super()}" } it_behaves_like 'immutable objects', %("\#{a}") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23c2711..be1363f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,6 +39,8 @@ config.fail_fast = ENV.key? 'RSPEC_FAIL_FAST' end + config.filter_run_excluding unsupported_on: :prism if ENV['PARSER_ENGINE'] == 'parser_prism' + config.disable_monkey_patching! config.order = :random From f6a2a340c2b21b4ef50f3b887360b1f89aa4864a Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Sun, 22 Sep 2024 22:49:58 +0300 Subject: [PATCH 3/6] Add prism testing to CI --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e112739..97a12ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,3 +43,19 @@ jobs: bundler: 2.3.26 - name: Run tests run: bundle exec rspec + + test-prism: + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: "gemfiles/rubocop_1.66.gemfile" + PARSER_ENGINE: parser_prism + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # 'bundle install' and cache gems + ruby-version: 3.3 + bundler: 2.3.26 + - name: Run tests + run: bundle exec rspec From 7a47d02c7e72be9e79802523c0fbf733e9dd582e Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Mon, 23 Sep 2024 10:15:51 +0300 Subject: [PATCH 4/6] Add MRI3 tests for `MutableClassInstanceVariable` cop --- .../mutable_class_instance_variable_spec.rb | 26 ++++++++++++++----- spec/spec_helper.rb | 7 +++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb b/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb index bc6346b..564b389 100644 --- a/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb +++ b/spec/rubocop/cop/thread_safety/mutable_class_instance_variable_spec.rb @@ -282,10 +282,16 @@ def some_method it_behaves_like 'mutable objects', %("\#{a}") end - context 'when the frozen_string_literal comment is true', unsupported_on: :prism do - let(:prefix) { "# frozen_string_literal: true\n#{super()}" } + context 'when the frozen_string_literal comment is true' do + context 'with Ruby 2.7', unsupported_on: :prism do + let(:prefix) { "# frozen_string_literal: true\n#{super()}" } - it_behaves_like 'immutable objects', %("\#{a}") + it_behaves_like 'immutable objects', %("\#{a}") + end + + context 'with Ruby 3', :ruby30 do + it_behaves_like 'mutable objects', %("\#{a}") + end end context 'when the frozen_string_literal comment is false' do @@ -605,10 +611,18 @@ def assignment? it_behaves_like 'mutable objects', %("\#{a}") end - context 'when the frozen_string_literal comment is true', unsupported_on: :prism do - let(:prefix) { "# frozen_string_literal: true\n#{super()}" } + context 'when the frozen_string_literal comment is true' do + context 'with Ruby 2.7', unsupported_on: :prism do + let(:prefix) { "# frozen_string_literal: true\n#{super()}" } - it_behaves_like 'immutable objects', %("\#{a}") + it_behaves_like 'immutable objects', %("\#{a}") + end + + context 'with Ruby 3', :ruby30 do + let(:prefix) { "# frozen_string_literal: true\n#{super()}" } + + it_behaves_like 'mutable objects', %("\#{a}") + end end context 'when the frozen_string_literal comment is false' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be1363f..0eaadf4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,4 +46,11 @@ config.order = :random Kernel.srand config.seed + + config.include_context 'ruby 2.7', :ruby27 + config.include_context 'ruby 3.0', :ruby30 + config.include_context 'ruby 3.1', :ruby31 + config.include_context 'ruby 3.2', :ruby32 + config.include_context 'ruby 3.3', :ruby33 + config.include_context 'ruby 3.4', :ruby34 end From 5875668fdec7579c2a3af974e11981e40134a854 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Mon, 23 Sep 2024 10:22:38 +0300 Subject: [PATCH 5/6] Try define shared contexts explicitly --- spec/shared_contexts.rb | 29 +++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 2 files changed, 30 insertions(+) create mode 100644 spec/shared_contexts.rb diff --git a/spec/shared_contexts.rb b/spec/shared_contexts.rb new file mode 100644 index 0000000..d7078b3 --- /dev/null +++ b/spec/shared_contexts.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.shared_context 'ruby 2.7' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.7 } +end + +RSpec.shared_context 'ruby 3.0' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.0 } +end + +RSpec.shared_context 'ruby 3.1' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.1 } +end + +RSpec.shared_context 'ruby 3.2' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.2 } +end + +RSpec.shared_context 'ruby 3.3' do + let(:ruby_version) { 3.3 } +end + +RSpec.shared_context 'ruby 3.4' do + let(:ruby_version) { 3.4 } +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0eaadf4..2c6f662 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,7 @@ require 'rubocop-thread_safety' require 'rubocop/rspec/support' +require_relative 'shared_contexts' RSpec.configure do |config| config.include RuboCop::RSpec::ExpectOffense From a155e816071e2a519f4d86099593cf378237f6d3 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Mon, 23 Sep 2024 10:29:19 +0300 Subject: [PATCH 6/6] Define shared context only for old rubocops --- .rubocop.yml | 4 ++++ spec/shared_contexts.rb | 44 +++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7615651..fd05c0f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -82,6 +82,10 @@ Style/SymbolArray: RSpec/ExampleLength: Max: 11 +RSpec/ContextWording: + Exclude: + - spec/shared_contexts.rb + Gemspec/DevelopmentDependencies: EnforcedStyle: gemspec diff --git a/spec/shared_contexts.rb b/spec/shared_contexts.rb index d7078b3..2e10fc9 100644 --- a/spec/shared_contexts.rb +++ b/spec/shared_contexts.rb @@ -1,29 +1,31 @@ # frozen_string_literal: true -RSpec.shared_context 'ruby 2.7' do - # Prism supports parsing Ruby 3.3+. - let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.7 } -end +unless RuboCop::Version.version >= '1.6' + RSpec.shared_context 'ruby 2.7' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.7 } + end -RSpec.shared_context 'ruby 3.0' do - # Prism supports parsing Ruby 3.3+. - let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.0 } -end + RSpec.shared_context 'ruby 3.0' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.0 } + end -RSpec.shared_context 'ruby 3.1' do - # Prism supports parsing Ruby 3.3+. - let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.1 } -end + RSpec.shared_context 'ruby 3.1' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.1 } + end -RSpec.shared_context 'ruby 3.2' do - # Prism supports parsing Ruby 3.3+. - let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.2 } -end + RSpec.shared_context 'ruby 3.2' do + # Prism supports parsing Ruby 3.3+. + let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.2 } + end -RSpec.shared_context 'ruby 3.3' do - let(:ruby_version) { 3.3 } -end + RSpec.shared_context 'ruby 3.3' do + let(:ruby_version) { 3.3 } + end -RSpec.shared_context 'ruby 3.4' do - let(:ruby_version) { 3.4 } + RSpec.shared_context 'ruby 3.4' do + let(:ruby_version) { 3.4 } + end end