Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Notifier & notify to Reporter & report #17

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
begin
1 / 0
rescue ZeroDivisionError => e
Telebugs.notify(error: e)
Telebugs.report(e)
end

sleep 2
Expand Down
6 changes: 3 additions & 3 deletions lib/telebugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require_relative "telebugs/version"
require_relative "telebugs/config"
require_relative "telebugs/promise"
require_relative "telebugs/notifier"
require_relative "telebugs/reporter"
require_relative "telebugs/sender"
require_relative "telebugs/wrapped_error"
require_relative "telebugs/report"
Expand All @@ -30,8 +30,8 @@ def configure
yield Config.instance
end

def notify(error:)
Notifier.instance.notify(error)
def report(error)
Reporter.instance.report(error)
end
end
end
2 changes: 0 additions & 2 deletions lib/telebugs/config.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

module Telebugs
# Represents the Telebugs config. A config contains all the options that you
# can use to configure a +Telebugs::Notifier+ instance.
class Config
ERROR_API_URL = "https://api.telebugs.com/2024-03-28/errors"

Expand Down
6 changes: 3 additions & 3 deletions lib/telebugs/notifier.rb → lib/telebugs/reporter.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

module Telebugs
# Notifier is reponsible for sending reports to Telebugs.
class Notifier
# Reporter is reponsible for sending reports to Telebugs.
class Reporter
class << self
attr_writer :instance

Expand All @@ -16,7 +16,7 @@ def initialize
@middleware = Config.instance.middleware
end

def notify(error)
def report(error)
Telebugs::Promise.new(error) do
report = Report.new(error)

Expand Down
14 changes: 7 additions & 7 deletions test/test_notifier.rb → test/test_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ def call(report)
end
end

class TestNotifier < Minitest::Test
class TestReporter < Minitest::Test
def teardown
WebMock.reset!
Telebugs::Config.instance.reset
end

def test_notify_returns_a_promise_that_resolves_to_a_hash
def test_report_returns_a_promise_that_resolves_to_a_hash
stub = stub_request(:post, Telebugs::Config.instance.api_url)
.to_return(status: 201, body: {id: "123"}.to_json)

p = Telebugs::Notifier.new.notify(StandardError.new)
p = Telebugs::Reporter.new.report(StandardError.new)

assert_equal({"id" => "123"}, p.value)
assert_requested stub
end

def test_notify_returns_a_promise_that_rejects_on_http_error
def test_reporter_returns_a_promise_that_rejects_on_http_error
stub = stub_request(:post, Telebugs::Config.instance.api_url)
.to_return(status: 500)

p = Telebugs::Notifier.new.notify(StandardError.new)
p = Telebugs::Reporter.new.report(StandardError.new)

assert_nil p.value
assert_instance_of(Telebugs::HTTPError, p.reason)
assert_requested stub
end

def test_notify_does_not_send_ignored_errors
def test_reporter_does_not_send_ignored_errors
stub = stub_request(:post, Telebugs::Config.instance.api_url)
.to_return(status: 201, body: {id: "123"}.to_json)

Telebugs.configure do |c|
c.middleware.use TestIgnoreMiddleware.new
end

p = Telebugs::Notifier.new.notify(StandardError.new)
p = Telebugs::Reporter.new.report(StandardError.new)
p.wait

refute_requested stub
Expand Down
8 changes: 4 additions & 4 deletions test/test_telebugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ def test_configure_configures_project_key
assert_equal key, Telebugs::Config.instance.api_key
end

def test_notify_returns_a_fullfilled_promise_when_request_succeeds
def test_report_returns_a_fullfilled_promise_when_request_succeeds
stub_request(:post, Telebugs::Config.instance.api_url)
.to_return(status: 201, body: {id: "123"}.to_json)

p = Telebugs.notify(error: StandardError.new)
p = Telebugs.report(StandardError.new)
p.wait

assert p.fulfilled?
end

def test_notify_returns_a_rejected_promise_when_request_fails
def test_report_returns_a_rejected_promise_when_request_fails
stub_request(:post, Telebugs::Config.instance.api_url).to_return(status: 500)

p = Telebugs.notify(error: StandardError.new)
p = Telebugs.report(StandardError.new)
p.wait

assert p.rejected?
Expand Down