mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
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:
@ -106,12 +106,11 @@ RSpec.describe DiscourseHub do
|
||||
end
|
||||
|
||||
describe ".collection_action" 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 log correctly on error" do
|
||||
stub_request(:get, (ENV["HUB_BASE_URL"] || "http://local.hub:3000/api") + "/test").to_return(
|
||||
@ -123,9 +122,9 @@ RSpec.describe DiscourseHub do
|
||||
|
||||
DiscourseHub.collection_action(:get, "/test")
|
||||
|
||||
expect(@fake_logger.warnings).to eq([DiscourseHub.response_status_log_message("/test", 500)])
|
||||
expect(fake_logger.warnings).to eq([DiscourseHub.response_status_log_message("/test", 500)])
|
||||
|
||||
expect(@fake_logger.errors).to eq([DiscourseHub.response_body_log_message("")])
|
||||
expect(fake_logger.errors).to eq([DiscourseHub.response_body_log_message("")])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user