Skip to content

Commit

Permalink
Merge pull request #11 from SOFware/log-errors
Browse files Browse the repository at this point in the history
Ensure that the logger is configurable
  • Loading branch information
saturnflyer authored Sep 21, 2024
2 parents 53f8f0c + 8773380 commit bc22c5e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.2.3] - Unreleased

### Fixed

- Incorrect configuration of the logger

## [0.2.2] - 2024-09-05

### Added
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ gem "rake"
gem "minitest"
gem "simplecov"
gem "simplecov-json"
gem "reissue"
gem "reissue"
gem "ostruct"
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GEM
reline (>= 0.4.2)
json (2.7.2)
minitest (5.24.1)
ostruct (0.6.0)
psych (5.1.2)
stringio
rake (13.2.1)
Expand Down Expand Up @@ -43,6 +44,7 @@ DEPENDENCIES
chat_notifier!
debug
minitest
ostruct
rake
reissue
simplecov
Expand Down
4 changes: 2 additions & 2 deletions lib/chat_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module ChatNotifier
DebugExceptionLocation = Data.define(:location)
DebugSummary = Data.define(:failed_examples)

require "logger"
@logger = Logger.new($stdout)
class << self
require "logger"
@logger = Logger.new($stdout)
attr_accessor :logger

def app
Expand Down
84 changes: 84 additions & 0 deletions test/chat_notifier_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
require "test_helper"
require "ostruct"
require "chat_notifier"

module ChatNotifier
class Test < Minitest::Test
def setup
# Setup any necessary test data or mocks here
@env = {} # Replace with actual environment data if needed
@summary = "Test summary"
end

def test_app_returns_rails_app_name
Object.const_set(
:Rails,
OpenStruct.new(
application: OpenStruct.new(
class: OpenStruct.new(
module_parent: "TestApp"
)
)
)
)
assert_equal "TestApp", ChatNotifier.app
end

def test_app_returns_env_name
ENV["NOTIFY_APP_NAME"] = "TestApp"
assert_equal "TestApp", ChatNotifier.app
end

def test_debug!
mock_repository = Minitest::Mock.new
mock_environment = Minitest::Mock.new
mock_chatter = Minitest::Mock.new(ChatNotifier::Chatter::Debug)
mock_messenger = Minitest::Mock.new

Repository.stub(:for, mock_repository) do
TestEnvironment.stub(:for, mock_environment) do
Chatter.stub(:const_get, mock_chatter) do
mock_chatter.expect(:new, mock_chatter, settings: @env, repository: mock_repository, environment: mock_environment)
Messenger.stub(:for, mock_messenger) do
mock_chatter.expect(:post, nil, [mock_messenger])

ChatNotifier.debug!(@env, summary: @summary)

mock_chatter.verify
end
end
end
end
end

def test_call
original_app_name = ENV["NOTIFY_APP_NAME"]
ENV["NOTIFY_APP_NAME"] = "TestApp"
# Mock dependencies
mock_repository = Minitest::Mock.new
mock_environment = Minitest::Mock.new
mock_messenger = Minitest::Mock.new
mock_box = Minitest::Mock.new

Repository.stub(:for, mock_repository) do
TestEnvironment.stub(:for, mock_environment) do
Chatter.stub(:handling, [mock_box]) do
Messenger.stub(:for, mock_messenger) do
mock_box.expect(:conditional_post, nil, [mock_messenger])

ChatNotifier.call(summary: @summary)

mock_box.verify
end
end
end
end
ensure
if original_app_name.nil?
ENV.delete("NOTIFY_APP_NAME")
else
ENV["NOTIFY_APP_NAME"] = original_app_name
end
end
end
end

0 comments on commit bc22c5e

Please sign in to comment.