diff options
Diffstat (limited to 'spec/rubocop/cop/database/rescue_statement_timeout_spec.rb')
-rw-r--r-- | spec/rubocop/cop/database/rescue_statement_timeout_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb new file mode 100644 index 00000000000..b9b2ce1c16b --- /dev/null +++ b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/database/rescue_statement_timeout' + +RSpec.describe RuboCop::Cop::Database::RescueStatementTimeout do + subject(:cop) { described_class.new } + + it 'flags the use of ActiveRecord::StatementTimeout' do + expect_offense(<<~CODE) + begin + do_something + rescue ActiveRecord::StatementTimeout => e + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid rescuing the `ActiveRecord::StatementTimeout` [...] + try_something_else + end + CODE + end + + it 'does not flag a different exception' do + expect_no_offenses(<<~CODE) + begin + do_something + rescue ActiveRecord::RecordNotFound => e + try_something_else + end + CODE + end +end |