Skip to content

Commit

Permalink
Make GovukError.configure behave as a singleton
Browse files Browse the repository at this point in the history
This is to prevent any surprising behaviour should the downstream
app decide to call 'GovukError.configure' twice. Prior to this
commit, calling twice would keep all the Raven configuration but
lose any custom configuration.

I then needed to edit the 'govuk_error_spec' configure test to
prevent `double("Configuration")` from leaking between tests. I
also found that the change would cause configuring_spec.rb to
fail, as the initialised GovukError module would no longer be
looking for the SENTRY_CURRENT_ENV variable at the time the test
would run.

Once I changed this test to accommodate the singleton pattern, we
no longer needed the `config.current_environment=` line, which was
only really there to satisfy configuring_spec.rb. The line is
unnecessary as the default behaviour is to delegate that to Raven,
which is already being set via the ENV variable, so we don't need
to create that ourselves. We also no longer need configuring_spec
itself - its behaviour is now tested in govuk_error_spec.
  • Loading branch information
ChrisBAshton committed Oct 14, 2020
1 parent 01d8df3 commit 92a83fa
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
3 changes: 2 additions & 1 deletion lib/govuk_app_config/govuk_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.notify(exception_or_message, args = {})
end

def self.configure
yield Configuration.new(Raven.configuration)
@configuration ||= Configuration.new(Raven.configuration)
yield @configuration
end
end
2 changes: 0 additions & 2 deletions lib/govuk_app_config/govuk_error/configure.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
GovukError.configure do |config|
config.current_environment = ENV["SENTRY_CURRENT_ENV"]

config.before_send = proc { |e|
GovukStatsd.increment("errors_occurred")
GovukStatsd.increment("error_types.#{e.class.name.demodulize.underscore}")
Expand Down
13 changes: 0 additions & 13 deletions spec/integration/configuring_spec.rb

This file was deleted.

6 changes: 2 additions & 4 deletions spec/lib/govuk_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

describe ".configure" do
it "configures Raven via the Configuration" do
mock_configuration = double("Configuration")
allow(GovukError::Configuration).to receive(:new) { mock_configuration }
expect(mock_configuration).to receive(:foo)
GovukError.configure(&:foo)
expect { |b| GovukError.configure(&b) }
.to yield_with_args(instance_of(GovukError::Configuration))
end
end
end

0 comments on commit 92a83fa

Please sign in to comment.