|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -RSpec.describe RuboCop::Cop::RSpec::DescribeClass do |
4 | | - subject(:cop) { described_class.new } |
5 | | - |
| 3 | +RSpec.describe RuboCop::Cop::RSpec::DescribeClass, :config do |
6 | 4 | it 'checks first-line describe statements' do |
7 | 5 | expect_offense(<<-RUBY) |
8 | 6 | describe "bad describe" do |
|
120 | 118 | end |
121 | 119 | end |
122 | 120 |
|
123 | | - it 'ignores request specs' do |
124 | | - expect_no_offenses(<<-RUBY) |
125 | | - describe 'my new feature', type: :request do |
126 | | - end |
127 | | - RUBY |
128 | | - end |
129 | | - |
130 | | - it 'ignores feature specs' do |
131 | | - expect_no_offenses(<<-RUBY) |
132 | | - describe 'my new feature', type: :feature do |
133 | | - end |
134 | | - RUBY |
135 | | - end |
136 | | - |
137 | | - it 'ignores system specs' do |
138 | | - expect_no_offenses(<<-RUBY) |
139 | | - describe 'my new system test', type: :system do |
140 | | - end |
141 | | - RUBY |
142 | | - end |
143 | | - |
144 | | - it 'ignores feature specs when RSpec.describe is used' do |
145 | | - expect_no_offenses(<<-RUBY) |
146 | | - RSpec.describe 'my new feature', type: :feature do |
147 | | - end |
148 | | - RUBY |
149 | | - end |
150 | | - |
151 | | - it 'flags specs with non :type metadata' do |
152 | | - expect_offense(<<-RUBY) |
153 | | - describe 'my new feature', foo: :feature do |
154 | | - ^^^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested. |
155 | | - end |
156 | | - RUBY |
157 | | - end |
158 | | - |
159 | | - it 'flags normal metadata in describe' do |
160 | | - expect_offense(<<-RUBY) |
161 | | - describe 'my new feature', blah, type: :wow do |
162 | | - ^^^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested. |
163 | | - end |
164 | | - RUBY |
165 | | - end |
166 | | - |
167 | | - it 'ignores feature specs - also with complex options' do |
168 | | - expect_no_offenses(<<-RUBY) |
169 | | - describe 'my new feature', :test, :type => :feature, :foo => :bar do |
170 | | - end |
171 | | - RUBY |
172 | | - end |
173 | | - |
174 | 121 | it 'ignores an empty describe' do |
175 | 122 | expect_no_offenses(<<-RUBY) |
176 | 123 | RSpec.describe do |
|
181 | 128 | RUBY |
182 | 129 | end |
183 | 130 |
|
184 | | - it 'ignores routing specs' do |
185 | | - expect_no_offenses(<<-RUBY) |
186 | | - describe 'my new route', type: :routing do |
187 | | - end |
188 | | - RUBY |
189 | | - end |
190 | | - |
191 | | - it 'ignores view specs' do |
192 | | - expect_no_offenses(<<-RUBY) |
193 | | - describe 'widgets/index', type: :view do |
194 | | - end |
195 | | - RUBY |
196 | | - end |
197 | | - |
198 | | - it "doesn't blow up on single-line describes" do |
199 | | - expect_no_offenses('describe Some::Class') |
200 | | - end |
201 | | - |
202 | 131 | it "doesn't flag top level describe in a shared example" do |
203 | 132 | expect_no_offenses(<<-RUBY) |
204 | 133 | shared_examples 'Common::Interface' do |
|
234 | 163 | end |
235 | 164 | RUBY |
236 | 165 | end |
| 166 | + |
| 167 | + it 'ignores `type` metadata ignored by default' do |
| 168 | + expect_no_offenses(<<-RUBY) |
| 169 | + describe 'widgets/index', type: :view do |
| 170 | + end |
| 171 | + RUBY |
| 172 | + end |
| 173 | + |
| 174 | + it 'flags specs with non `type` metadata' do |
| 175 | + expect_offense(<<-RUBY) |
| 176 | + describe 'foo bar', foo: :bar do |
| 177 | + ^^^^^^^^^ The first argument to describe should be the class or module being tested. |
| 178 | + end |
| 179 | + RUBY |
| 180 | + end |
| 181 | + |
| 182 | + it 'ignores feature specs - also with complex options' do |
| 183 | + expect_no_offenses(<<-RUBY) |
| 184 | + describe 'my new feature', :test, foo: :bar, type: :feature do |
| 185 | + end |
| 186 | + RUBY |
| 187 | + end |
| 188 | + |
| 189 | + it 'flags non-ignored `type` metadata' do |
| 190 | + expect_offense(<<-RUBY) |
| 191 | + describe 'wow', blah, type: :wow do |
| 192 | + ^^^^^ The first argument to describe should be the class or module being tested. |
| 193 | + end |
| 194 | + RUBY |
| 195 | + end |
| 196 | + |
| 197 | + context 'when IgnoredMetadata is configured' do |
| 198 | + let(:cop_config) do |
| 199 | + { 'IgnoredMetadata' => |
| 200 | + { 'foo' => ['bar'], |
| 201 | + 'type' => ['wow'] } } |
| 202 | + end |
| 203 | + |
| 204 | + it 'ignores configured metadata' do |
| 205 | + expect_no_offenses(<<-RUBY) |
| 206 | + describe 'foo bar', foo: :bar do |
| 207 | + end |
| 208 | + RUBY |
| 209 | + end |
| 210 | + |
| 211 | + it 'ignores configured `type` metadata' do |
| 212 | + expect_no_offenses(<<-RUBY) |
| 213 | + describe 'my new system test', type: :wow do |
| 214 | + end |
| 215 | + RUBY |
| 216 | + end |
| 217 | + end |
237 | 218 | end |
0 commit comments