DEV: Remove the use of stubs on Rails.logger in our test suite.

This commit is contained in:
Guo Xiang Tan
2018-10-10 09:34:50 +08:00
parent 9b01e2b855
commit f26804394a
6 changed files with 79 additions and 37 deletions

View File

@ -77,23 +77,28 @@ describe DiscourseHub do
end
describe '.collection_action' do
it 'should log a warning if status is not 200' do
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api")).
to_return(status: 500, body: "", headers: {})
Rails.logger.expects(:warn)
DiscourseHub.collection_action(:get, "")
before do
@orig_logger = Rails.logger
Rails.logger = @fake_logger = FakeLogger.new
end
it 'should log an error if response is invalid JSON' do
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api")).
to_return(status: 200, body: "this is not valid JSON", headers: {})
after do
Rails.logger = @orig_logger
end
Rails.logger.expects(:error)
it 'should log correctly on error' do
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api/test")).
to_return(status: 500, body: "", headers: {})
DiscourseHub.collection_action(:get, "")
DiscourseHub.collection_action(:get, '/test')
expect(Rails.logger.warnings).to eq([
DiscourseHub.response_status_log_message('/test', 500),
])
expect(Rails.logger.errors).to eq([
DiscourseHub.response_body_log_message("")
])
end
end
end