diff options
Diffstat (limited to 'spec/rubocop/formatter')
-rw-r--r-- | spec/rubocop/formatter/graceful_formatter_spec.rb | 9 | ||||
-rw-r--r-- | spec/rubocop/formatter/todo_formatter_spec.rb | 70 |
2 files changed, 70 insertions, 9 deletions
diff --git a/spec/rubocop/formatter/graceful_formatter_spec.rb b/spec/rubocop/formatter/graceful_formatter_spec.rb index 0e0c1d52067..1ed8533ac16 100644 --- a/spec/rubocop/formatter/graceful_formatter_spec.rb +++ b/spec/rubocop/formatter/graceful_formatter_spec.rb @@ -2,7 +2,8 @@ require 'fast_spec_helper' require 'rspec-parameterized' -require 'rubocop/rspec/shared_contexts' +require 'rubocop' +require 'rubocop/rspec/support' require 'stringio' require_relative '../../../rubocop/formatter/graceful_formatter' @@ -225,14 +226,14 @@ RSpec.describe RuboCop::Formatter::GracefulFormatter, :isolated_environment do cop_name: cop_name, corrected?: false, correctable?: false, - severity: double(:severity, name: 'convention', code: :C), + severity: double(:severity, name: :convention, code: :C), line: 5, column: 23, real_column: 23, corrected_with_todo?: false, message: "#{cop_name} message", - location: double(:location, source_line: 'line', first_line: 1, last_line: 2), - highlighted_area: double(:highlighted_area, begin_pos: 1, size: 2) + location: double(:location, source_line: 'line', first_line: 1, last_line: 1, single_line?: true), + highlighted_area: double(:highlighted_area, begin_pos: 1, size: 2, source_buffer: 'line', source: 'i') ) # rubocop:enable RSpec/VerifiedDoubles end diff --git a/spec/rubocop/formatter/todo_formatter_spec.rb b/spec/rubocop/formatter/todo_formatter_spec.rb index edd84632409..5494d518605 100644 --- a/spec/rubocop/formatter/todo_formatter_spec.rb +++ b/spec/rubocop/formatter/todo_formatter_spec.rb @@ -82,7 +82,7 @@ RSpec.describe RuboCop::Formatter::TodoFormatter do expect(todo_yml('B/AutoCorrect')).to eq(<<~YAML) --- - # Cop supports --auto-correct. + # Cop supports --autocorrect. B/AutoCorrect: Exclude: - 'd.rb' @@ -309,18 +309,78 @@ RSpec.describe RuboCop::Formatter::TodoFormatter do context 'without offenses detected' do before do + todo_dir.write('A/Cop', yaml) if yaml + todo_dir.inspect_all + formatter.started(%w[a.rb b.rb]) formatter.file_finished('a.rb', []) formatter.file_finished('b.rb', []) formatter.finished(%w[a.rb b.rb]) + + todo_dir.delete_inspected end - it 'does not output anything' do - expect(stdout.string).to eq('') + context 'without existing TODOs' do + let(:yaml) { nil } + + it 'does not output anything' do + expect(stdout.string).to eq('') + end + + it 'does not write any YAML files' do + expect(rubocop_todo_dir_listing).to be_empty + end end - it 'does not write any YAML files' do - expect(rubocop_todo_dir_listing).to be_empty + context 'with existing TODOs' do + context 'when existing offenses only' do + let(:yaml) do + <<~YAML + --- + A/Cop: + Exclude: + - x.rb + YAML + end + + it 'does not output anything' do + expect(stdout.string).to eq('') + end + + it 'does not write any YAML files' do + expect(rubocop_todo_dir_listing).to be_empty + end + end + + context 'when in grace period' do + let(:yaml) do + <<~YAML + --- + A/Cop: + Details: grace period + Exclude: + - x.rb + YAML + end + + it 'outputs its actions' do + expect(stdout.string).to eq(<<~OUTPUT) + Written to .rubocop_todo/a/cop.yml + OUTPUT + end + + it 'creates YAML file with Details only', :aggregate_failures do + expect(rubocop_todo_dir_listing).to contain_exactly( + 'a/cop.yml' + ) + + expect(todo_yml('A/Cop')).to eq(<<~YAML) + --- + A/Cop: + Details: grace period + YAML + end + end end end |