DEV: Don’t replace Rails logger in specs (#29721)

Instead of replacing the Rails logger in specs, we can instead use
`#broadcast_to` which has been introduced in Rails 7.
This commit is contained in:
Loïc Guitaut
2024-11-13 01:47:39 +01:00
committed by GitHub
parent 907fbd6f1e
commit d637bd6519
17 changed files with 113 additions and 127 deletions

View File

@ -426,12 +426,11 @@ RSpec.describe ApplicationController do
end
describe "no logspam" do
before do
@orig_logger = Rails.logger
Rails.logger = @fake_logger = FakeLogger.new
end
let(:fake_logger) { FakeLogger.new }
after { Rails.logger = @orig_logger }
before { Rails.logger.broadcast_to(fake_logger) }
after { Rails.logger.stop_broadcasting_to(fake_logger) }
it "should handle 404 to a css file" do
Discourse.cache.delete("page_not_found_topics:#{I18n.locale}")
@ -453,9 +452,9 @@ RSpec.describe ApplicationController do
expect(response.body).to include(topic1.title)
expect(response.body).to_not include(topic2.title)
expect(@fake_logger.fatals.length).to eq(0)
expect(@fake_logger.errors.length).to eq(0)
expect(@fake_logger.warnings.length).to eq(0)
expect(fake_logger.fatals.length).to eq(0)
expect(fake_logger.errors.length).to eq(0)
expect(fake_logger.warnings.length).to eq(0)
end
end