forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_describes.rb
43 lines (38 loc) · 1.09 KB
/
multiple_describes.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
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks for multiple top-level example groups.
#
# Multiple descriptions for the same class or module should either
# be nested or separated into different test files.
#
# @example
# # bad
# describe MyClass, '.do_something' do
# end
# describe MyClass, '.do_something_else' do
# end
#
# # good
# describe MyClass do
# describe '.do_something' do
# end
# describe '.do_something_else' do
# end
# end
#
class MultipleDescribes < Base
include TopLevelGroup
MSG = 'Do not use multiple top-level example groups - try to nest them.'
def on_top_level_group(node)
top_level_example_groups =
top_level_groups.select(&method(:example_group?))
return if top_level_example_groups.one?
return unless top_level_example_groups.first.equal?(node)
add_offense(node.send_node)
end
end
end
end
end