|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | RSpec.describe RuboCop::Cop::RSpec::Dialect do
|
4 |
| - let(:cop_config) do |
5 |
| - { |
6 |
| - 'PreferredMethods' => { |
7 |
| - 'context' => 'describe' |
8 |
| - } |
9 |
| - } |
10 |
| - end |
| 4 | + context 'with preferred methods' do |
| 5 | + context 'when `describe` is preferred to `context`' do |
| 6 | + let(:cop_config) do |
| 7 | + { |
| 8 | + 'PreferredMethods' => { |
| 9 | + 'context' => 'describe' |
| 10 | + } |
| 11 | + } |
| 12 | + end |
11 | 13 |
|
12 |
| - it 'allows describe blocks' do |
13 |
| - expect_no_offenses(<<~RUBY) |
14 |
| - describe 'display name presence' do |
| 14 | + it 'allows describe blocks' do |
| 15 | + expect_no_offenses(<<~RUBY) |
| 16 | + RSpec.describe 'context' do |
| 17 | + describe 'display name presence' do |
| 18 | + end |
| 19 | + end |
| 20 | + RUBY |
15 | 21 | end
|
16 |
| - RUBY |
17 |
| - end |
18 | 22 |
|
19 |
| - it 'allows calling methods named context in examples' do |
20 |
| - expect_no_offenses(<<~RUBY) |
21 |
| - it 'tests common context invocations' do |
22 |
| - expect(request.context).to be_empty? |
| 23 | + it 'registers an offense for context blocks' do |
| 24 | + expect_offense(<<~RUBY) |
| 25 | + RSpec.describe 'context' do |
| 26 | + context 'display name presence' do |
| 27 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`. |
| 28 | + end |
| 29 | + end |
| 30 | + RUBY |
| 31 | + |
| 32 | + expect_correction(<<~RUBY) |
| 33 | + RSpec.describe 'context' do |
| 34 | + describe 'display name presence' do |
| 35 | + end |
| 36 | + end |
| 37 | + RUBY |
23 | 38 | end
|
24 |
| - RUBY |
25 |
| - end |
| 39 | + end |
26 | 40 |
|
27 |
| - it 'registers an offense for context blocks' do |
28 |
| - expect_offense(<<~RUBY) |
29 |
| - context 'display name presence' do |
30 |
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`. |
| 41 | + context 'when `describe` is preferred to `feature`' do |
| 42 | + let(:cop_config) do |
| 43 | + { |
| 44 | + 'PreferredMethods' => { |
| 45 | + 'feature' => 'describe' |
| 46 | + } |
| 47 | + } |
31 | 48 | end
|
32 |
| - RUBY |
33 | 49 |
|
34 |
| - expect_correction(<<~RUBY) |
35 |
| - describe 'display name presence' do |
| 50 | + it 'allows describe blocks' do |
| 51 | + expect_no_offenses(<<~RUBY) |
| 52 | + RSpec.describe 'context' do |
| 53 | + describe 'display name presence' do |
| 54 | + end |
| 55 | + end |
| 56 | + RUBY |
36 | 57 | end
|
37 |
| - RUBY |
38 |
| - end |
39 | 58 |
|
40 |
| - it 'registers an offense for RSpec.context blocks' do |
41 |
| - expect_offense(<<~RUBY) |
42 |
| - RSpec.context 'context' do |
43 |
| - ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`. |
44 |
| - it 'tests common context invocations' do |
45 |
| - expect(request.context).to be_empty? |
46 |
| - end |
| 59 | + it 'registers an offense for feature blocks' do |
| 60 | + expect_offense(<<~RUBY) |
| 61 | + RSpec.describe 'context' do |
| 62 | + feature 'display name presence' do |
| 63 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `feature`. |
| 64 | + end |
| 65 | + end |
| 66 | + RUBY |
| 67 | + |
| 68 | + expect_correction(<<~RUBY) |
| 69 | + RSpec.describe 'context' do |
| 70 | + describe 'display name presence' do |
| 71 | + end |
| 72 | + end |
| 73 | + RUBY |
47 | 74 | end
|
48 |
| - RUBY |
| 75 | + end |
49 | 76 |
|
50 |
| - expect_correction(<<~RUBY) |
51 |
| - RSpec.describe 'context' do |
52 |
| - it 'tests common context invocations' do |
53 |
| - expect(request.context).to be_empty? |
54 |
| - end |
| 77 | + context 'when `let` is preferred to `given`' do |
| 78 | + let(:cop_config) do |
| 79 | + { |
| 80 | + 'PreferredMethods' => { |
| 81 | + 'given' => 'let' |
| 82 | + } |
| 83 | + } |
| 84 | + end |
| 85 | + |
| 86 | + it 'allows let blocks' do |
| 87 | + expect_no_offenses(<<~RUBY) |
| 88 | + RSpec.describe 'context' do |
| 89 | + let do |
| 90 | + end |
| 91 | + end |
| 92 | + RUBY |
55 | 93 | end
|
56 |
| - RUBY |
| 94 | + |
| 95 | + it 'registers an offense for given blocks' do |
| 96 | + expect_offense(<<~RUBY) |
| 97 | + RSpec.describe 'context' do |
| 98 | + given do |
| 99 | + ^^^^^ Prefer `let` over `given`. |
| 100 | + end |
| 101 | + end |
| 102 | + RUBY |
| 103 | + |
| 104 | + expect_correction(<<~RUBY) |
| 105 | + RSpec.describe 'context' do |
| 106 | + let do |
| 107 | + end |
| 108 | + end |
| 109 | + RUBY |
| 110 | + end |
| 111 | + end |
| 112 | + |
| 113 | + context 'when `let!` is preferred to `given!`' do |
| 114 | + let(:cop_config) do |
| 115 | + { |
| 116 | + 'PreferredMethods' => { |
| 117 | + 'given!' => 'let!' |
| 118 | + } |
| 119 | + } |
| 120 | + end |
| 121 | + |
| 122 | + it 'allows let! blocks' do |
| 123 | + expect_no_offenses(<<~RUBY) |
| 124 | + RSpec.describe 'context' do |
| 125 | + let! do |
| 126 | + end |
| 127 | + end |
| 128 | + RUBY |
| 129 | + end |
| 130 | + |
| 131 | + it 'registers an offense for given! blocks' do |
| 132 | + expect_offense(<<~RUBY) |
| 133 | + RSpec.describe 'context' do |
| 134 | + given! do |
| 135 | + ^^^^^^ Prefer `let!` over `given!`. |
| 136 | + end |
| 137 | + end |
| 138 | + RUBY |
| 139 | + |
| 140 | + expect_correction(<<~RUBY) |
| 141 | + RSpec.describe 'context' do |
| 142 | + let! do |
| 143 | + end |
| 144 | + end |
| 145 | + RUBY |
| 146 | + end |
| 147 | + end |
| 148 | + |
| 149 | + context 'when `before` is preferred to `background`' do |
| 150 | + let(:cop_config) do |
| 151 | + { |
| 152 | + 'PreferredMethods' => { |
| 153 | + 'background' => 'before' |
| 154 | + } |
| 155 | + } |
| 156 | + end |
| 157 | + |
| 158 | + it 'allows before blocks' do |
| 159 | + expect_no_offenses(<<~RUBY) |
| 160 | + RSpec.describe 'context' do |
| 161 | + before do |
| 162 | + end |
| 163 | + end |
| 164 | + RUBY |
| 165 | + end |
| 166 | + |
| 167 | + it 'registers an offense for background blocks' do |
| 168 | + expect_offense(<<~RUBY) |
| 169 | + RSpec.describe 'context' do |
| 170 | + background do |
| 171 | + ^^^^^^^^^^ Prefer `before` over `background`. |
| 172 | + end |
| 173 | + end |
| 174 | + RUBY |
| 175 | + |
| 176 | + expect_correction(<<~RUBY) |
| 177 | + RSpec.describe 'context' do |
| 178 | + before do |
| 179 | + end |
| 180 | + end |
| 181 | + RUBY |
| 182 | + end |
| 183 | + end |
57 | 184 | end
|
58 | 185 |
|
59 | 186 | context 'without preferred methods' do
|
|
65 | 192 |
|
66 | 193 | it 'allows all methods blocks' do
|
67 | 194 | expect_no_offenses(<<~RUBY)
|
68 |
| - context 'is important' do |
69 |
| - specify 'for someone to work' do |
70 |
| - everyone.should have_some_leeway |
| 195 | + RSpec.describe 'context' do |
| 196 | + context 'is important' do |
| 197 | + specify 'for someone to work' do |
| 198 | + everyone.should have_some_leeway |
| 199 | + end |
71 | 200 | end
|
72 | 201 | end
|
73 | 202 | RUBY
|
|
0 commit comments