Skip to content

Commit

Permalink
Skip DescribeClass cop for feature/request specs
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rodríguez committed Mar 13, 2015
1 parent 549440c commit 6d9c47c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/rubocop/cop/rspec/describe_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,25 @@ class DescribeClass < Cop
'module being tested.'

def on_top_level_describe(_node, args)
return if args.first && args.first.type == :const
add_offense(args.first, :expression, MESSAGE)
return if args[0] && args[0].type == :const

return if request_spec?(args[1]) || feature_spec?(args[1])

add_offense(args[0], :expression, MESSAGE)
end

private

def request_spec?(node)
return false unless node

node.loc.expression.source == 'type: :request' || ':type => :request'
end

def feature_spec?(node)
return false unless node

node.loc.expression.source == 'type: :feature' || ':type => :feature'
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/rspec/describe_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
expect(cop.offenses).to be_empty
end

it 'ignores request specs' do
inspect_source(cop, "describe 'my new feature', type: :request do; end")
expect(cop.offenses).to be_empty
end

it 'ignores feature specs' do
inspect_source(cop, "describe 'my new feature', type: :feature do; end")
expect(cop.offenses).to be_empty
end

it "doesn't blow up on single-line describes" do
inspect_source(cop, 'describe Some::Class')
expect(cop.offenses).to be_empty
Expand Down

0 comments on commit 6d9c47c

Please sign in to comment.