spec/rubocop/cop/rspec/multiple_expectations_spec.rb in rubocop-rspec-1.33.0 vs spec/rubocop/cop/rspec/multiple_expectations_spec.rb in rubocop-rspec-1.34.0
- old
+ new
@@ -94,120 +94,147 @@
end
RUBY
end
end
- context 'with meta data' do
+ context 'with metadata' do
it 'ignores examples with `:aggregate_failures`' do
expect_no_offenses(<<-RUBY)
describe Foo do
- it 'uses expect twice', :aggregate_failures do
+ it 'uses expect twice', :foo, :aggregate_failures do
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- it 'ignores examples with `aggregate_failures: true`' do
+ it 'ignores example groups with `:aggregate_failures`' do
expect_no_offenses(<<-RUBY)
- describe Foo do
- it 'uses expect twice', aggregate_failures: true do
+ describe Foo, :foo, :aggregate_failures do
+ it 'uses expect twice' do
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- it 'checks examples with `aggregate_failures: false`' do
- expect_offense(<<-RUBY)
+ it 'ignores examples with `aggregate_failures: true`' do
+ expect_no_offenses(<<-RUBY)
describe Foo do
- it 'uses expect twice', aggregate_failures: false do
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
+ it 'uses expect twice', :foo, bar: 1, aggregate_failures: true do
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- end
- context 'with Max configuration' do
- let(:cop_config) do
- { 'Max' => '2' }
- end
-
- it 'permits two expectations' do
+ it 'ignores example groups with `aggregate_failures: true`' do
expect_no_offenses(<<-RUBY)
- describe Foo do
+ describe Foo, :foo, bar: 1, aggregate_failures: true do
it 'uses expect twice' do
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- it 'flags three expectations' do
+ it 'prefers example metadata over example group metadata' do
expect_offense(<<-RUBY)
- describe Foo do
- it 'uses expect three times' do
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2].
+ describe Foo, aggregate_failures: true do
+ it 'uses expect twice', aggregate_failures: false do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
- expect(qux).to eq(bar)
end
end
RUBY
end
- end
- context 'with AggregateFailuresByDefault configuration' do
- let(:cop_config) do
- { 'AggregateFailuresByDefault' => true }
+ it 'checks examples with `aggregate_failures: false`' do
+ expect_offense(<<-RUBY)
+ describe Foo do
+ it 'uses expect twice', aggregate_failures: false do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
+ expect(foo).to eq(bar)
+ expect(baz).to eq(bar)
+ end
+ end
+ RUBY
end
- it 'ignores examples without metadata' do
- expect_no_offenses(<<-RUBY)
- describe Foo do
+ it 'checks example groups with `aggregate_failures: false`' do
+ expect_offense(<<-RUBY)
+ describe Foo, aggregate_failures: false do
it 'uses expect twice' do
+ ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- it 'ignores examples with `:aggregate_failures`' do
- expect_no_offenses(<<-RUBY)
+ it 'checks examples with siblings with `aggregate_failures: true`' do
+ expect_offense(<<-RUBY)
describe Foo do
- it 'uses expect twice', :aggregate_failures do
+ it 'uses expect twice' do
+ ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
+ it 'with aggregate_failures', aggregate_failures: true do
+ expect(foo).to eq(bar)
+ expect(baz).to eq(bar)
+ end
end
RUBY
end
- it 'ignores examples with `aggregate_failures: true`' do
+ it 'ignores examples with `aggregate_failures: true` defined deeply' do
expect_no_offenses(<<-RUBY)
+ describe Bar, aggregate_failures: true do
+ describe Foo do
+ it 'uses expect twice' do
+ expect(foo).to eq(bar)
+ expect(baz).to eq(bar)
+ end
+ it 'with aggregate_failures', aggregate_failures: false do
+ expect(foo).to eq(bar)
+ end
+ end
+ end
+ RUBY
+ end
+ end
+
+ context 'with Max configuration' do
+ let(:cop_config) do
+ { 'Max' => '2' }
+ end
+
+ it 'permits two expectations' do
+ expect_no_offenses(<<-RUBY)
describe Foo do
- it 'uses expect twice', aggregate_failures: true do
+ it 'uses expect twice' do
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
end
- it 'checks examples with `aggregate_failures: false`' do
+ it 'flags three expectations' do
expect_offense(<<-RUBY)
describe Foo do
- it 'uses expect twice', aggregate_failures: false do
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
+ it 'uses expect three times' do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
+ expect(qux).to eq(bar)
end
end
RUBY
end
end