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 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/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' 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..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 @@ -283,9 +283,15 @@ def some_method end context 'when the frozen_string_literal comment is true' do - let(:prefix) { "# frozen_string_literal: true\n#{super()}" } + 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 @@ -606,9 +612,17 @@ def assignment? end context 'when the frozen_string_literal comment is true' do - let(:prefix) { "# frozen_string_literal: true\n#{super()}" } + 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/shared_contexts.rb b/spec/shared_contexts.rb new file mode 100644 index 0000000..2e10fc9 --- /dev/null +++ b/spec/shared_contexts.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +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.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 +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23c2711..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 @@ -39,9 +40,18 @@ 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 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