Skip to content

Commit

Permalink
Use assert_nothing_raised from Rails
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Nov 6, 2024
1 parent cbc1e25 commit 21258a9
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "mocha/minitest"
require "ruby_lsp/test_helper"
require "ruby_lsp/ruby_lsp_rails/addon"
require "active_support/testing/assertions" # for assert_nothing_raised

if defined?(DEBUGGER__)
DEBUGGER__::CONFIG[:skip_path] =
Expand All @@ -24,6 +25,7 @@ module Minitest
class Test
extend T::Sig
include RubyLsp::TestHelper
include ActiveSupport::Testing::Assertions # for assert_nothing_raised

def dummy_root
File.expand_path("#{__dir__}/dummy")
Expand Down Expand Up @@ -57,35 +59,5 @@ def pop_message(outgoing_queue, &block)
message = outgoing_queue.pop until block.call(message)
message
end

# Copied from Rails
def assert_nothing_raised(*args)
msg = if Module === args.last
nil
else
args.pop
end
begin
line = __LINE__
yield
rescue MiniTest::Skip
raise
rescue Exception => e # rubocop:disable Lint/RescueException
bt = e.backtrace
as = e.instance_of?(MiniTest::Assertion)
if as
ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /
bt.reject! { |ln| ans =~ ln }
end
if (args.empty? && !as) ||
args.any? { |a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a }
msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
raise MiniTest::Assertion, msg.call, bt
else
raise
end
end
nil
end
end
end

0 comments on commit 21258a9

Please sign in to comment.