spec/rubocop/cop/rspec/described_class_spec.rb in rubocop-rspec-1.5.1 vs spec/rubocop/cop/rspec/described_class_spec.rb in rubocop-rspec-1.5.2
- old
+ new
@@ -1,7 +1,5 @@
-# encoding: utf-8
-
describe RuboCop::Cop::RSpec::DescribedClass do
subject(:cop) { described_class.new }
it 'checks for the use of the described class' do
inspect_source(
@@ -121,9 +119,41 @@
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line).sort).to eq([2])
expect(cop.messages)
.to eq(['Use `described_class` instead of `MyNamespace::MyClass`'])
expect(cop.highlights).to eq(['MyNamespace::MyClass'])
+ end
+
+ it 'does not flag violations within a scope change' do
+ inspect_source(
+ cop,
+ [
+ 'describe MyNamespace::MyClass do',
+ ' before do',
+ ' class Foo',
+ ' thing = MyNamespace::MyClass.new',
+ ' end',
+ ' end',
+ 'end'
+ ]
+ )
+
+ expect(cop.offenses).to be_empty
+ end
+
+ it 'does not flag violations within a scope change' do
+ inspect_source(
+ cop,
+ [
+ 'describe do',
+ ' before do',
+ ' MyNamespace::MyClass.new',
+ ' end',
+ 'end'
+ ]
+ )
+
+ expect(cop.offenses).to be_empty
end
it 'checks for the use of described class with module' do
skip
inspect_source(