Skip to content

Commit

Permalink
Skip DescribeMethod cop for tagged specs
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rodríguez committed Mar 13, 2015
1 parent 6d9c47c commit 8c3d74d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/describe_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DescribeMethod < Cop

def on_top_level_describe(_node, args)
second_arg = args[1]
return unless second_arg
return unless second_arg && second_arg.type == :str
return if METHOD_STRING_MATCHER =~ second_arg.children.first

add_offense(second_arg, :expression, MESSAGE)
Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/cop/rspec/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def on_top_level_describe(node, args)
object = const_name(args.first)
return unless object

path_matcher = matcher(object, args[1])
method = args[1]
return unless method.nil? || method.type == :str

path_matcher = matcher(object, method)
return if source_filename =~ regexp_from_glob(path_matcher)

add_offense(node, :expression, format(MESSAGE, path_matcher))
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rspec/describe_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
"describe Some::Class, '#fdsa' do; end"])
expect(cop.offenses).to be_empty
end

it 'skips specs not having a string second argument' do
inspect_source(cop, 'describe Some::Class, :config do; end')

expect(cop.offenses).to be_empty
end
end
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rspec/file_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
expect(cop.offenses).to be_empty
end

it 'skips specs not having a string second argument' do
inspect_source(cop, 'describe Some::Class, :config do; end')

expect(cop.offenses).to be_empty
end

it 'checks class specs' do
inspect_source(cop,
'describe Some::Class do; end',
Expand Down

0 comments on commit 8c3d74d

Please sign in to comment.