forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
describe_method.rb
35 lines (31 loc) · 906 Bytes
/
describe_method.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
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks that the second argument to `describe` specifies a method.
#
# @example
# # bad
# describe MyClass, 'do something' do
# end
#
# # good
# describe MyClass, '#my_instance_method' do
# end
#
# describe MyClass, '.my_class_method' do
# end
class DescribeMethod < Cop
include RuboCop::RSpec::TopLevelDescribe
include RuboCop::RSpec::Util
MSG = 'The second argument to describe should be the method '\
"being tested. '#instance' or '.class'."
def on_top_level_describe(_node, (_, second_arg))
return unless second_arg&.str_type?
return if second_arg.str_content.start_with?('#', '.')
add_offense(second_arg)
end
end
end
end
end