Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tasks/rubocop_rake_spec.rb')
-rw-r--r--spec/tasks/rubocop_rake_spec.rb39
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') }