spec/rubocop/cop/rspec/describe_class_spec.rb in rubocop-rspec-1.5.1 vs spec/rubocop/cop/rspec/describe_class_spec.rb in rubocop-rspec-1.5.2

- old
+ new

@@ -1,7 +1,5 @@ -# encoding: utf-8 - describe RuboCop::Cop::RSpec::DescribeClass do subject(:cop) { described_class.new } it 'checks first-line describe statements' do inspect_source(cop, 'describe "bad describe" do; end') @@ -9,10 +7,15 @@ expect(cop.offenses.map(&:line).sort).to eq([1]) expect(cop.messages).to eq(['The first argument to describe should be ' \ 'the class or module being tested.']) end + it 'supports RSpec.describe' do + inspect_source(cop, 'RSpec.describe Foo do; end') + expect(cop.offenses).to be_empty + end + it 'checks describe statements after a require' do inspect_source( cop, [ "require 'spec_helper'", @@ -23,10 +26,15 @@ expect(cop.offenses.map(&:line).sort).to eq([2]) expect(cop.messages).to eq(['The first argument to describe should be ' \ 'the class or module being tested.']) end + it 'checks highlights the first argument of a describe' do + inspect_source(cop, 'describe "bad describe", "blah blah" do; end') + expect(cop.offenses.first.location.column_range).to eq(9...23) + end + it 'ignores nested describe statements' do inspect_source( cop, [ 'describe Some::Class do', @@ -45,18 +53,44 @@ it 'ignores feature specs' do inspect_source(cop, "describe 'my new feature', type: :feature do; end") expect(cop.offenses).to be_empty end + it 'ignores feature specs when RSpec.describe is used' do + inspect_source( + cop, + "RSpec.describe 'my new feature', type: :feature do; end" + ) + + expect(cop.offenses).to be_empty + end + + it 'flags specs with non :type metadata' do + inspect_source(cop, "describe 'my new feature', foo: :feature do; end") + expect(cop.messages).to eq(['The first argument to describe should be ' \ + 'the class or module being tested.']) + end + + it 'flags normal metadata in describe' do + inspect_source(cop, "describe 'my new feature', blah, type: :wow do; end") + expect(cop.messages).to eq(['The first argument to describe should be ' \ + 'the class or module being tested.']) + end + it 'ignores feature specs - also with complex options' do inspect_source( cop, [ "describe 'my new feature',", ' :test, :type => :feature, :foo => :bar do;', 'end' ] ) + expect(cop.offenses).to be_empty + end + + it 'ignores an empty describe' do + inspect_source(cop, 'describe do; end') expect(cop.offenses).to be_empty end it 'ignores routing specs' do inspect_source(cop, "describe 'my new route', type: :routing do; end")