diff options
Diffstat (limited to 'spec/rubocop/cop')
-rw-r--r-- | spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb new file mode 100644 index 00000000000..75a1f939a9f --- /dev/null +++ b/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/with_lock_retries_with_change' + +describe RuboCop::Cop::Migration::WithLockRetriesWithChange do + include CopHelper + + subject(:cop) { described_class.new } + + context 'in migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + it 'registers an offense when `with_lock_retries` is used inside a `change` method' do + inspect_source('def change; with_lock_retries {}; end') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + + it 'registers no offense when `with_lock_retries` is used inside an `up` method' do + inspect_source('def up; with_lock_retries {}; end') + + expect(cop.offenses.size).to eq(0) + end + end + + context 'outside of migration' do + it 'registers no offense' do + inspect_source('def change; with_lock_retries {}; end') + + expect(cop.offenses.size).to eq(0) + end + end +end |