spec/rubocop/cop/rspec/expect_actual_spec.rb in rubocop-rspec-1.12.0 vs spec/rubocop/cop/rspec/expect_actual_spec.rb in rubocop-rspec-1.13.0
- old
+ new
@@ -1,59 +1,59 @@
# frozen_string_literal: true
-describe RuboCop::Cop::RSpec::ExpectActual do
- subject(:cop) { described_class.new }
+RSpec.describe RuboCop::Cop::RSpec::ExpectActual, :config do
+ subject(:cop) { described_class.new(config) }
it 'flags numeric literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(123).to eq(bar)
- ^^^ Provide the actual you are testing to `expect(...)`
+ ^^^ Provide the actual you are testing to `expect(...)`.
expect(12.3).to eq(bar)
- ^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^ Provide the actual you are testing to `expect(...)`.
expect(1i).to eq(bar)
- ^^ Provide the actual you are testing to `expect(...)`
+ ^^ Provide the actual you are testing to `expect(...)`.
expect(1r).to eq(bar)
- ^^ Provide the actual you are testing to `expect(...)`
+ ^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags boolean literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(true).to eq(bar)
- ^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^ Provide the actual you are testing to `expect(...)`.
expect(false).to eq(bar)
- ^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags string and symbol literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect("foo").to eq(bar)
- ^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
expect(:foo).to eq(bar)
- ^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags literal nil value within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(nil).to eq(bar)
- ^^^ Provide the actual you are testing to `expect(...)`
+ ^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
@@ -72,65 +72,80 @@
it 'flags arrays containing only literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect([123]).to eq(bar)
- ^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
expect([[123]]).to eq(bar)
- ^^^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags hashes containing only literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(foo: 1, bar: 2).to eq(bar)
- ^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
expect(foo: 1, bar: [{}]).to eq(bar)
- ^^^^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags ranges containing only literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(1..2).to eq(bar)
- ^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^ Provide the actual you are testing to `expect(...)`.
expect(1...2).to eq(bar)
- ^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'flags regexps containing only literal values within expect(...)' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect incorrectly' do
expect(/foo|bar/).to eq(bar)
- ^^^^^^^^^ Provide the actual you are testing to `expect(...)`
+ ^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
end
end
RUBY
end
it 'does not flag complex values with dynamic parts within expect(...)' do
expect_no_violations(<<-'RUBY')
describe Foo do
it 'uses expect incorrectly' do
+ expect.to eq(bar)
expect([foo]).to eq(bar)
expect([[foo]]).to eq(bar)
expect(foo: 1, bar: foo).to eq(bar)
expect(1..foo).to eq(bar)
expect(1...foo).to eq(bar)
expect(/foo|#{bar}/).to eq(bar)
end
end
RUBY
+ end
+
+ context 'when inspecting rspec-rails routing specs' do
+ let(:cop_config) { {} }
+
+ it 'ignores rspec-rails routing specs' do
+ inspect_source(
+ cop,
+ 'expect(get: "/foo").to be_routeable',
+ 'spec/routing/foo_spec.rb'
+ )
+
+ expect(cop.offenses).to be_empty
+ end
end
end