spec/rubocop/cop/rspec/expect_change_spec.rb in rubocop-rspec-1.32.0 vs spec/rubocop/cop/rspec/expect_change_spec.rb in rubocop-rspec-1.33.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
RSpec.describe RuboCop::Cop::RSpec::ExpectChange, :config do
subject(:cop) { described_class.new(config) }
let(:cop_config) do
{ 'EnforcedStyle' => enforced_style }
@@ -9,14 +11,20 @@
let(:enforced_style) { 'method_call' }
it 'finds blocks that contain simple message sending' do
expect_offense(<<-RUBY)
it do
- expect(run).to change { User.count }
+ expect(run).to change { User.count }.by(1)
^^^^^^^^^^^^^^^^^^^^^ Prefer `change(User, :count)`.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ it do
+ expect(run).to change(User, :count).by(1)
+ end
+ RUBY
end
it 'ignores blocks that cannot be converted to obj/attribute pair' do
expect_no_offenses(<<-RUBY)
it do
@@ -30,49 +38,49 @@
it do
Record.change { User.count }
end
RUBY
end
-
- include_examples(
- 'autocorrect',
- 'expect(run).to change { User.count }.by(1)',
- 'expect(run).to change(User, :count).by(1)'
- )
end
context 'with EnforcedStyle `block`' do
let(:enforced_style) { 'block' }
it 'finds change matcher without block' do
expect_offense(<<-RUBY)
it do
- expect(run).to change(User, :count)
+ expect(run).to change(User, :count).by(1)
^^^^^^^^^^^^^^^^^^^^ Prefer `change { User.count }`.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ it do
+ expect(run).to change { User.count }.by(1)
+ end
+ RUBY
end
it 'finds change matcher when receiver is a variable' do
expect_offense(<<-RUBY)
it do
expect(run).to change(user, :count)
^^^^^^^^^^^^^^^^^^^^ Prefer `change { user.count }`.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ it do
+ expect(run).to change { user.count }
+ end
+ RUBY
end
it 'ignores methods called change' do
expect_no_offenses(<<-RUBY)
it do
record.change(user, :count)
end
RUBY
end
-
- include_examples(
- 'autocorrect',
- 'expect(run).to change(User, :count).by(1)',
- 'expect(run).to change { User.count }.by(1)'
- )
end
end