Skip to content

Commit

Permalink
Use assert_nothing_raised in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Feb 10, 2024
1 parent ddac0f7 commit 6f15101
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Style/MapToHash:
Style/FetchEnvVar:
Enabled: false

Style/RescueStandardError:
Enabled: false

Style/DisableSyntax:
DisableSyntax:
- unless
Expand Down
2 changes: 1 addition & 1 deletion lib/online_migrations/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module OnlineMigrations
module DatabaseTasks
def migrate(*)
super
rescue => e # rubocop:disable Style/RescueStandardError
rescue => e
if e.cause.is_a?(OnlineMigrations::Error)
# strip cause
def e.cause
Expand Down
7 changes: 4 additions & 3 deletions test/schema_statements/misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ def test_add_exclusion_constraint
def test_add_exclusion_constraint_is_idempotent
skip if ar_version < 7.1

2.times do
@connection.add_exclusion_constraint(:invoices, "daterange(start_date, end_date) WITH &&", using: :gist)
assert_nothing_raised do
2.times do
@connection.add_exclusion_constraint(:invoices, "daterange(start_date, end_date) WITH &&", using: :gist)
end
end
assert true # rubocop:disable Minitest/UselessAssertion
end

def test_swap_column_names
Expand Down
7 changes: 7 additions & 0 deletions test/support/minitest_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ def assert_raises_with_message(exception_class, message, &block)
assert_match message, error.message
end

def assert_nothing_raised
yield
assert true # rubocop:disable Minitest/UselessAssertion
rescue => e
raise Minitest::UnexpectedError.new(e) # rubocop:disable Style/RaiseArgs
end

def migrate(migration, direction: :up, version: 1)
connection = ActiveRecord::Base.connection

Expand Down

0 comments on commit 6f15101

Please sign in to comment.