diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/tasks/rubocop_rake_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/tasks/rubocop_rake_spec.rb')
-rw-r--r-- | spec/tasks/rubocop_rake_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/tasks/rubocop_rake_spec.rb b/spec/tasks/rubocop_rake_spec.rb index a92d7dc2e52..eb360cdff93 100644 --- a/spec/tasks/rubocop_rake_spec.rb +++ b/spec/tasks/rubocop_rake_spec.rb @@ -3,16 +3,20 @@ require 'fast_spec_helper' require 'rake' +require 'tmpdir' require 'fileutils' require_relative '../support/silence_stdout' require_relative '../support/helpers/next_instance_of' require_relative '../support/helpers/rake_helpers' +require_relative '../support/matchers/abort_matcher' require_relative '../../rubocop/formatter/todo_formatter' require_relative '../../rubocop/todo_dir' +require_relative '../../rubocop/check_graceful_task' RSpec.describe 'rubocop rake tasks', :silence_stdout do include RakeHelpers + include NextInstanceOf before do stub_const('Rails', double(:rails_env)) @@ -23,6 +27,41 @@ RSpec.describe 'rubocop rake tasks', :silence_stdout do Rake.application.rake_require 'tasks/rubocop' end + describe 'check:graceful' do + let(:options) { %w[file.rb Cop/Name] } + + subject(:run_task) { run_rake_task('rubocop:check:graceful', *options) } + + before do + allow_next_instance_of(RuboCop::CheckGracefulTask, $stdout) do |task| + allow(task).to receive(:run).with(options).and_return(task_result) + end + end + + context 'with successful task result' do + let(:task_result) { 0 } + + # We cannot use `abort_execution` because it's ignoring exit status `0`. + # Rely on SystemExitDetected here. + specify { run_task } + + it 'modifies ENV and deletes REVEAL_RUBOCOP_TODO key' do + # There's ENV backup in before block. + ENV['REVEAL_RUBOCOP_TODO'] = '0' # rubocop:disable RSpec/EnvAssignment + + run_task + + expect(ENV.key?('REVEAL_RUBOCOP_TODO')).to eq(false) + end + end + + context 'with non-successful task result' do + let(:task_result) { 1 } + + specify { expect { run_task }.to abort_execution } + end + end + describe 'todo:generate', :aggregate_failures do let(:tmp_dir) { Dir.mktmpdir } let(:rubocop_todo_dir) { File.join(tmp_dir, '.rubocop_todo') } |