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

- old
+ new

@@ -1,10 +1,7 @@ -# encoding: utf-8 - describe RuboCop::Cop::RSpec::FilePath, :config do subject(:cop) { described_class.new(config) } - let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } } it 'checks the path' do inspect_source( cop, "describe MyClass, 'foo' do; end", @@ -26,10 +23,40 @@ expect(cop.offenses.map(&:line).sort).to eq([1]) expect(cop.messages) .to eq(['Spec path should end with `my_class*foo*_spec.rb`']) end + it 'flags foo_spec.rb.rb' do + inspect_source( + cop, + "describe MyClass, '#foo' do; end", + 'my_class/foo_spec.rb.rb' + ) + expect(cop.offenses.size).to eq(1) + end + + it 'flags foo_specorb' do + inspect_source( + cop, + "describe MyClass, '#foo' do; end", + 'my_class/foo_specorb' + ) + expect(cop.offenses.size).to eq(1) + end + + it 'checks path even when metadata is included' do + inspect_source( + cop, + "describe MyClass, '#foo', blah: :blah do; end", + 'wrong_class_foo_spec.rb' + ) + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line).sort).to eq([1]) + expect(cop.messages) + .to eq(['Spec path should end with `my_class*foo*_spec.rb`']) + end + it 'checks class spec paths' do inspect_source( cop, 'describe MyClass do; end', 'wrong_class_spec.rb' @@ -110,12 +137,12 @@ end it 'handles alphanumeric class names' do inspect_source( cop, - 'describe IPV6 do; end', - 'ipv6_spec.rb' + 'describe IPv4AndIPv6 do; end', + 'i_pv4_and_i_pv6_spec.rb' ) expect(cop.offenses).to be_empty end it 'checks instance methods' do @@ -179,41 +206,54 @@ 'some/class/pred_spec.rb' ) expect(cop.offenses).to be_empty end - it 'allows flexibility with predicates' do + it 'allows bang method' do inspect_source( cop, - "describe Some::Class, '#thing?' do; end", - 'some/class/thing_predicate_spec.rb' + "describe Some::Class, '#bang!' do; end", + 'some/class/bang_spec.rb' ) expect(cop.offenses).to be_empty end - it 'allows flexibility with operators' do + it 'allows flexibility with predicates' do inspect_source( cop, - "describe MyClass, '#<=>' do; end", - 'my_class/spaceship_operator_spec.rb' + "describe Some::Class, '#thing?' do; end", + 'some/class/thing_predicate_spec.rb' ) expect(cop.offenses).to be_empty end - it 'respects custom module name transformation' do + it 'allows flexibility with operators' do inspect_source( cop, - "describe FooFoo::Some::Class, '#bar' do; end", - 'foofoo/some/class/bar_spec.rb' + "describe MyLittleClass, '#<=>' do; end", + 'my_little_class/spaceship_operator_spec.rb' ) expect(cop.offenses).to be_empty end - it 'ignores routing specs' do - inspect_source( - cop, - 'describe MyController, type: :routing do; end', - 'foofoo/some/class/bar_spec.rb' - ) - expect(cop.offenses).to be_empty + context 'when configured' do + let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } } + + it 'respects custom module name transformation' do + inspect_source( + cop, + "describe FooFoo::Some::Class, '#bar' do; end", + 'foofoo/some/class/bar_spec.rb' + ) + expect(cop.offenses).to be_empty + end + + it 'ignores routing specs' do + inspect_source( + cop, + 'describe MyController, "#foo", type: :routing do; end', + 'foofoo/some/class/bar_spec.rb' + ) + expect(cop.offenses).to be_empty + end end end