diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8f5d150..baf2d16 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -18,21 +18,17 @@ permissions: jobs: test: - - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: - ruby-version: ['3.0', '3.4'] + ruby-version: ['3.0', '3.1', '3.2', '3.3'] steps: - uses: actions/checkout@v4 - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically + bundler-cache: true - name: Run tests run: bundle exec rake diff --git a/fast.gemspec b/fast.gemspec index 045b15c..e214155 100644 --- a/fast.gemspec +++ b/fast.gemspec @@ -47,6 +47,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'parallel' spec.add_dependency 'parser' spec.add_dependency 'pg_query' + spec.add_dependency 'racc' spec.add_development_dependency 'bundler' spec.add_development_dependency 'git' diff --git a/spec/fast/cli_spec.rb b/spec/fast/cli_spec.rb index 7ebc72f..1249870 100644 --- a/spec/fast/cli_spec.rb +++ b/spec/fast/cli_spec.rb @@ -6,20 +6,20 @@ RSpec.describe Fast::Cli do def highlight(output) - CodeRay.scan(output, :ruby).term + output # Remove syntax highlighting in tests end describe '.initialize' do subject(:cli) { described_class.new args } context 'with expression and file' do - let(:args) { %w[def lib/fast.rb] } + let(:args) { %w[--no-color def lib/fast.rb] } its(:pattern) { is_expected.to eq('def') } end context 'with expression and folders' do - let(:args) { %w[def lib/fast spec/fast] } + let(:args) { %w[--no-color def lib/fast spec/fast] } its(:pattern) { is_expected.to eq('def') } end @@ -130,21 +130,20 @@ def highlight(output) end context 'with search in file' do - let(:args) { %w[casgn lib/fast/version.rb] } + let(:args) { %w[--no-color casgn lib/fast/version.rb] } it 'prints file with line number' do - expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout + expect { cli.run! }.to output(<<~RUBY).to_stdout # lib/fast/version.rb:4 \s\sVERSION = '#{Fast::VERSION}' RUBY end context 'when the code is not from the beginning of the line' do - let(:args) { %w[str lib/fast/version.rb] } + let(:args) { %w[--no-color str lib/fast/version.rb] } it 'prints fragment of line' do - cli.run! - expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout + expect { cli.run! }.to output(<<~RUBY).to_stdout # lib/fast/version.rb:4 '#{Fast::VERSION}' RUBY @@ -152,10 +151,10 @@ def highlight(output) end context 'with args to print ast' do - let(:args) { %w[casgn lib/fast/version.rb --ast] } + let(:args) { %w[--no-color casgn lib/fast/version.rb --ast] } it 'prints ast instead of source code' do - expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout + expect { cli.run! }.to output(<<~RUBY).to_stdout # lib/fast/version.rb:4 (casgn nil :VERSION (str "#{Fast::VERSION}")) @@ -164,7 +163,7 @@ def highlight(output) end context 'with shortcut' do - let(:args) { ['.show_version'] } + let(:args) { %w[--no-color .show_version] } before do Fast.shortcuts.delete :show_version @@ -174,7 +173,7 @@ def highlight(output) its(:pattern) { is_expected.to eq('(casgn nil _ (str _))') } it 'uses the predefined values from the shortcut' do - expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout + expect { cli.run! }.to output(<<~RUBY).to_stdout # lib/fast/version.rb:4 VERSION = '#{Fast::VERSION}' RUBY @@ -182,10 +181,10 @@ def highlight(output) end context 'with args --headless --captures' do - let(:args) { ['(casgn nil _ (str $_))', 'lib/fast/version.rb', '--captures', '--headless'] } + let(:args) { %w[--no-color (casgn nil _ (str $_)) lib/fast/version.rb --captures --headless] } it 'prints only captured scope' do - expect { cli.run! }.to output("#{highlight(Fast::VERSION)}\n").to_stdout + expect { cli.run! }.to output("#{Fast::VERSION}\n").to_stdout end end end @@ -204,16 +203,16 @@ def highlight(output) let(:ast) { Fast.ast('a = 1') } it 'highlight the code with file in the header' do - allow(Fast).to receive(:highlight).with('# some_file.rb:1', colorize: true).and_call_original - allow(Fast).to receive(:highlight).with(ast, show_sexp: false, colorize: true).and_call_original - expect { Fast.report(ast, file: 'some_file.rb', show_sexp: false) } - .to output(highlight("# some_file.rb:1\na = 1\n")).to_stdout + allow(Fast).to receive(:highlight).with('# some_file.rb:1', colorize: false).and_call_original + allow(Fast).to receive(:highlight).with(ast, show_sexp: false, colorize: false).and_call_original + expect { Fast.report(ast, file: 'some_file.rb', show_sexp: false, colorize: false) } + .to output("# some_file.rb:1\na = 1\n").to_stdout end context 'with headless option' do it 'highlight the code without the file printed in the header' do - expect { Fast.report(ast, file: 'some_file.rb', headless: true) } - .to output(highlight("a = 1\n")).to_stdout + expect { Fast.report(ast, file: 'some_file.rb', headless: true, colorize: false) } + .to output("a = 1\n").to_stdout end end end