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

Run tests with prism parser #53

Merged
merged 6 commits into from
Sep 24, 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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Style/SymbolArray:
RSpec/ExampleLength:
Max: 11

RSpec/ContextWording:
Exclude:
- spec/shared_contexts.rb

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec

Expand Down
1 change: 1 addition & 0 deletions rubocop-thread_safety.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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