|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe RuboCop::Cop::InternalAffairs::ExampleDescription, :config do |
| 4 | + context 'with `expect_offense`' do |
| 5 | + it 'registers an offense when given an improper description' do |
| 6 | + expect_offense(<<~RUBY) |
| 7 | + it 'does not register an offense' do |
| 8 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_offense`. |
| 9 | + expect_offense('code') |
| 10 | + end |
| 11 | + RUBY |
| 12 | + end |
| 13 | + |
| 14 | + it 'does not register an offense when given a proper description' do |
| 15 | + expect_no_offenses(<<~RUBY) |
| 16 | + it 'finds an offense' do |
| 17 | + expect_offense('code') |
| 18 | + end |
| 19 | + RUBY |
| 20 | + end |
| 21 | + |
| 22 | + it 'does not register an offense when given an unexpected description' do |
| 23 | + expect_no_offenses(<<~RUBY) |
| 24 | + it 'foo bar baz' do |
| 25 | + expect_offense('code') |
| 26 | + end |
| 27 | + RUBY |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'with `expect_no_offenses`' do |
| 32 | + it 'registers an offense when given an improper description' do |
| 33 | + expect_offense(<<~RUBY) |
| 34 | + it 'registers an offense' do |
| 35 | + ^^^^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_no_offenses`. |
| 36 | + expect_no_offenses('code') |
| 37 | + end |
| 38 | + RUBY |
| 39 | + end |
| 40 | + |
| 41 | + it 'does not register an offense when given a proper description' do |
| 42 | + expect_no_offenses(<<~RUBY) |
| 43 | + it 'does not flag' do |
| 44 | + expect_no_offense('code') |
| 45 | + end |
| 46 | + RUBY |
| 47 | + end |
| 48 | + |
| 49 | + it 'does not register an offense when given an unexpected description' do |
| 50 | + expect_no_offenses(<<~RUBY) |
| 51 | + it 'foo bar baz' do |
| 52 | + expect_offense('code') |
| 53 | + end |
| 54 | + RUBY |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context 'with `expect_correction`' do |
| 59 | + it 'registers an offense when given an improper description' do |
| 60 | + expect_offense(<<~RUBY) |
| 61 | + it 'does not auto-correct' do |
| 62 | + ^^^^^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_correction`. |
| 63 | + expect_correction('code', source: 'new code') |
| 64 | + end |
| 65 | + RUBY |
| 66 | + end |
| 67 | + |
| 68 | + context 'in conjunction with expect_offense' do |
| 69 | + it 'registers an offense when given an improper description' do |
| 70 | + expect_offense(<<~RUBY) |
| 71 | + it 'registers an offense but does not auto-correct' do |
| 72 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_correction`. |
| 73 | + expect_offense('code') |
| 74 | + expect_correction('code') |
| 75 | + end |
| 76 | + RUBY |
| 77 | + end |
| 78 | + |
| 79 | + context 'when the description is invalid for both methods' do |
| 80 | + it 'registers an offense for the first method encountered' do |
| 81 | + expect_offense(<<~RUBY) |
| 82 | + it 'does not register an offense and does not auto-correct' do |
| 83 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_offense`. |
| 84 | + expect_offense('code') |
| 85 | + expect_correction('code') |
| 86 | + end |
| 87 | + RUBY |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + context 'with `expect_no_corrections`' do |
| 94 | + it 'registers an offense when given an improper description' do |
| 95 | + expect_offense(<<~RUBY) |
| 96 | + it 'autocorrects' do |
| 97 | + ^^^^^^^^^^^^^^ Description does not match use of `expect_no_corrections`. |
| 98 | + expect_no_corrections |
| 99 | + end |
| 100 | + RUBY |
| 101 | + end |
| 102 | + |
| 103 | + context 'in conjunction with expect_offense' do |
| 104 | + it 'registers an offense when given an improper description' do |
| 105 | + expect_offense(<<~RUBY) |
| 106 | + it 'auto-corrects' do |
| 107 | + ^^^^^^^^^^^^^^^ Description does not match use of `expect_no_corrections`. |
| 108 | + expect_offense('code') |
| 109 | + expect_no_corrections |
| 110 | + end |
| 111 | + RUBY |
| 112 | + end |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + context 'when not making an expectation on offenses' do |
| 117 | + it 'does not register an offense' do |
| 118 | + expect_no_offenses(<<~RUBY) |
| 119 | + it 'registers an offense' do |
| 120 | + end |
| 121 | + RUBY |
| 122 | + end |
| 123 | + end |
| 124 | +end |
0 commit comments