spec/rubocop/cop/rspec/multiple_expectations_spec.rb in rubocop-rspec-1.12.0 vs spec/rubocop/cop/rspec/multiple_expectations_spec.rb in rubocop-rspec-1.13.0
- old
+ new
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-describe RuboCop::Cop::RSpec::MultipleExpectations, :config do
+RSpec.describe RuboCop::Cop::RSpec::MultipleExpectations, :config do
subject(:cop) { described_class.new(config) }
context 'without configuration' do
let(:cop_config) { Hash.new }
it 'flags multiple expectations' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect twice' do
- ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]
+ ^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
end
RUBY
@@ -29,12 +29,75 @@
expect(cool).to be(true)
end
end
RUBY
end
+
+ it 'counts aggregate_failures as one expectation' do
+ expect_no_violations(<<-RUBY)
+ describe Foo do
+ it 'aggregates failures' do
+ aggregate_failures do
+ expect(foo).to eq(bar)
+ expect(baz).to eq(bar)
+ end
+ end
+ end
+ RUBY
+ end
+
+ it 'counts every aggregate_failures as an expectation' do
+ expect_violation(<<-RUBY)
+ describe Foo do
+ it 'has multiple aggregate_failures calls' do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
+ aggregate_failures do
+ end
+ aggregate_failures do
+ end
+ end
+ end
+ RUBY
+ end
end
+ context 'with meta data' do
+ it 'ignores examples with `:aggregate_failures`' do
+ expect_no_violations(<<-RUBY)
+ describe Foo do
+ it 'uses expect twice', :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
+ expect_no_violations(<<-RUBY)
+ describe Foo do
+ it 'uses expect twice', aggregate_failures: true do
+ expect(foo).to eq(bar)
+ expect(baz).to eq(bar)
+ end
+ end
+ RUBY
+ end
+
+ it 'checks examples with `aggregate_failures: false`' do
+ expect_violation(<<-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
+ end
+
context 'with configuration' do
let(:cop_config) do
{ 'Max' => '2' }
end
@@ -51,10 +114,10 @@
it 'flags three expectations' do
expect_violation(<<-RUBY)
describe Foo do
it 'uses expect three times' do
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2].
expect(foo).to eq(bar)
expect(baz).to eq(bar)
expect(qux).to eq(bar)
end
end