/
described_class_module_wrapping_spec.rb
47 lines (41 loc) · 1.19 KB
/
described_class_module_wrapping_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::DescribedClassModuleWrapping do
it 'allows a describe block in the outermost scope' do
expect_no_offenses(<<-RUBY)
RSpec.describe MyClass do
subject { "MyClass" }
end
RUBY
end
it 'registers an offense when RSpec.describe is nested within a module' do
expect_offense(<<-RUBY)
module MyModule
^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
RSpec.describe MyClass do
subject { "MyClass" }
end
end
RUBY
end
it 'registers an offense when RSpec.describe is nested within two modules' do
expect_offense(<<-RUBY)
module MyFirstModule
^^^^^^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
module MySecondModule
^^^^^^^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
RSpec.describe MyClass do
subject { "MyClass" }
end
end
end
RUBY
end
it 'allows a module that does not contain RSpec.describe' do
expect_no_offenses(<<-RUBY)
module MyModule
def some_method
end
end
RUBY
end
end