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

refactor!: remove second opts argument in Honeybadger.notify #499

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ def initialize(opts = {})
#
# @return [String] UUID reference to the notice within Honeybadger.
# @return [false] when ignored.
def notify(exception_or_opts = nil, opts = {}, **kwargs)
def notify(exception_or_opts = nil, **opts)
opts = opts.dup
opts.merge!(kwargs)

if exception_or_opts.is_a?(Exception)
already_reported_notice_id = exception_or_opts.instance_variable_get(:@__hb_notice_id)
Expand Down
4 changes: 2 additions & 2 deletions lib/honeybadger/singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ module Honeybadger
# @!method notify(...)
# Forwards to {Agent.instance}.
# @see Agent#notify
def notify(exception_or_opts=nil, opts = {}, **kwargs)
def notify(exception_or_opts = nil, **opts)
# Note this is defined directly (instead of via forwardable) so that
# generated stack traces work as expected.
Agent.instance.notify(exception_or_opts, opts, **kwargs)
Agent.instance.notify(exception_or_opts, **opts)
end

# @api private
Expand Down
29 changes: 3 additions & 26 deletions spec/unit/honeybadger/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,22 @@
opts = {error_message: 'test'}
prev = opts.dup
instance = described_class.new(Honeybadger::Config.new(api_key: "fake api key", logger: NULL_LOGGER))
instance.notify('test', opts)
instance.notify('test', **opts)
expect(prev).to eq(opts)
end

it "does take keyword arguments" do
opts = {error_message: 'test'}
config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER)
instance = described_class.new(config)

expect(instance.worker).to receive(:push) do |notice|
expect(notice.error_message).to match('test')
end
instance.notify(**opts)
end

it "does take keyword arguments as second argument" do
it "accepts keyword arguments as second argument" do
opts = {tags: 'testing, kwargs'}
config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER)
instance = described_class.new(config)

expect(instance.worker).to receive(:push) do |notice|
expect(notice.error_message).to match('test')
expect(notice.tags).to eq(['testing', 'kwargs'])
end
instance.notify('test', **opts)
end

it "does take explicit hash as second argument" do
opts = {tags: 'testing, hash'}
config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER)
instance = described_class.new(config)

expect(instance.worker).to receive(:push) do |notice|
expect(notice.error_message).to match('test')
expect(notice.tags).to eq(['testing', 'hash'])
end
instance.notify('test', opts)
end

it "does not report an already reported exception" do
instance = described_class.new(Honeybadger::Config.new(api_key: "fake api key", logger: NULL_LOGGER))
exception = RuntimeError.new
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/honeybadger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@
Honeybadger.notify(error_message: 'uh oh')
end

it "creates and sends a notice for an exception and hash" do
it "creates and sends a notice for an exception with additional arguments" do
exception = build_exception
notice = stub_notice!(config)
notice_args = { error_message: 'uh oh' }

expect(Honeybadger::Notice).to receive(:new).with(config, hash_including(notice_args.merge(exception: exception))).and_return(notice)
expect(worker).to receive(:push).with(notice)

Honeybadger.notify(exception, notice_args)
Honeybadger.notify(exception, **notice_args)
end

it "sends a notice with a string" do
Expand Down