Skip to content
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
6 changes: 5 additions & 1 deletion lib/raven/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ def exception_class_allowed?(exc)
end
end

def enabled_in_current_env?
environments.empty? || environments.include?(current_environment)
end

private

def detect_project_root
Expand Down Expand Up @@ -423,7 +427,7 @@ def detect_release_from_env
end

def capture_in_current_environment?
return true unless environments.any? && !environments.include?(current_environment)
return true if enabled_in_current_env?

@errors << "Not configured to send/capture in environment '#{current_environment}'"
false
Expand Down
1 change: 1 addition & 0 deletions lib/raven/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def client

# Tell the log that the client is good to go
def report_status
return unless configuration.enabled_in_current_env?
return if configuration.silence_ready

if configuration.capture_allowed?
Expand Down
47 changes: 30 additions & 17 deletions spec/raven/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,42 @@ def ivars(object)
end

let(:not_ready_message) do
"Raven #{Raven::VERSION} configured not to capture errors."
"Raven #{Raven::VERSION} configured not to capture errors: DSN not set"
end

it 'logs a ready message when configured' do
subject.configuration.silence_ready = false
context "when current environment is included in environments" do
before do
subject.configuration.silence_ready = false
subject.configuration.environments = ["default"]
end

expect(subject.logger).to receive(:info).with(ready_message)
subject.report_status
end
it 'logs a ready message when configured' do
expect(subject.logger).to receive(:info).with(ready_message)
subject.report_status
end

it 'logs a warning message when not properly configured' do
# dsn not set
subject.configuration = Raven::Configuration.new

it 'logs not ready message if the config does not send in current environment' do
subject.configuration.silence_ready = false
subject.configuration.environments = ["production"]
expect(subject.logger).to receive(:info).with(
"Raven #{Raven::VERSION} configured not to capture errors: Not configured to send/capture in environment 'default'"
)
subject.report_status
expect(subject.logger).to receive(:info).with(not_ready_message)
subject.report_status
end

it 'logs nothing if "silence_ready" configuration is true' do
subject.configuration.silence_ready = true
expect(subject.logger).not_to receive(:info)
subject.report_status
end
end

it 'logs nothing if "silence_ready" configuration is true' do
subject.configuration.silence_ready = true
expect(subject.logger).not_to receive(:info)
subject.report_status
context "when current environment is not included in environments" do
it "doesn't log any message" do
subject.configuration.silence_ready = false
subject.configuration.environments = ["production"]
expect(subject.logger).not_to receive(:info)
subject.report_status
end
end
end

Expand Down