Skip to content

Commit 3f90177

Browse files
committed
Fix clutter in test output
1 parent d71203f commit 3f90177

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

lib/raven/cli.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
module Raven
22
class CLI
3-
def self.test(dsn = nil)
4-
require 'logger'
3+
def self.test(dsn = nil, silent = false)
4+
if silent
5+
Raven.configuration.logger = ::Logger.new(nil)
6+
else
7+
logger = ::Logger.new(STDOUT)
8+
logger.level = ::Logger::ERROR
9+
logger.formatter = proc do |_severity, _datetime, _progname, msg|
10+
"-> #{msg}\n"
11+
end
512

6-
logger = ::Logger.new(STDOUT)
7-
logger.level = ::Logger::ERROR
8-
logger.formatter = proc do |_severity, _datetime, _progname, msg|
9-
"-> #{msg}\n"
13+
Raven.configuration.logger = logger
1014
end
1115

12-
Raven.configuration.logger = logger
1316
Raven.configuration.timeout = 5
1417
Raven.configuration.dsn = dsn if dsn
1518

1619
# wipe out env settings to ensure we send the event
1720
unless Raven.configuration.capture_in_current_environment?
1821
env_name = Raven.configuration.environments.pop || 'production'
19-
puts "Setting environment to #{env_name}"
22+
Raven.logger.debug "Setting environment to #{env_name}"
2023
Raven.configuration.current_environment = env_name
2124
end
2225

2326
Raven.configuration.verify!
2427

25-
puts "Sending a test event:"
26-
puts ""
28+
Raven.logger.debug "Sending a test event:"
29+
Raven.logger.debug ""
2730

2831
begin
2932
1 / 0
@@ -33,24 +36,24 @@ def self.test(dsn = nil)
3336

3437
if evt && !(evt.is_a? Thread)
3538
if evt.is_a? Hash
36-
puts "-> event ID: #{evt[:event_id]}"
39+
Raven.logger.debug "-> event ID: #{evt[:event_id]}"
3740
else
38-
puts "-> event ID: #{evt.id}"
41+
Raven.logger.debug "-> event ID: #{evt.id}"
3942
end
4043
elsif evt #async configuration
4144
if evt.value.is_a? Hash
42-
puts "-> event ID: #{evt.value[:event_id]}"
45+
Raven.logger.debug "-> event ID: #{evt.value[:event_id]}"
4346
else
44-
puts "-> event ID: #{evt.value.id}"
47+
Raven.logger.debug "-> event ID: #{evt.value.id}"
4548
end
4649
else
47-
puts ""
48-
puts "An error occurred while attempting to send the event."
50+
Raven.logger.debug ""
51+
Raven.logger.debug "An error occurred while attempting to send the event."
4952
exit 1
5053
end
5154

52-
puts ""
53-
puts "Done!"
55+
Raven.logger.debug ""
56+
Raven.logger.debug "Done!"
5457
end
5558
end
5659
end

spec/raven/cli_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
end
99

1010
Raven.configure do |config|
11-
config.server = 'http://12345:67890@sentry.localdomain/sentry/42'
1211
config.environments = ["test"]
1312
config.current_environment = "test"
1413
config.http_adapter = [:test, stubs]
14+
config.silence_ready = true
1515
end
1616

17-
Raven::CLI.test
17+
dsn = 'http://12345:67890@sentry.localdomain/sentry/42'
18+
Raven::CLI.test(dsn, true)
1819

1920
stubs.verify_stubbed_calls
2021
end
@@ -28,9 +29,11 @@
2829
config.environments = ["test"]
2930
config.current_environment = "test"
3031
config.http_adapter = [:test, stubs]
32+
config.silence_ready = true
3133
end
3234

33-
Raven::CLI.test 'http://12345:67890@sentry.localdomain/prefix/sentry/42'
35+
dsn = 'http://12345:67890@sentry.localdomain/prefix/sentry/42'
36+
Raven::CLI.test(dsn, true)
3437

3538
stubs.verify_stubbed_calls
3639
end

spec/raven/integrations/rails_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
Raven.configure do |config|
88
config.dsn = 'dummy://notaserver'
99
config.encoding = 'json'
10-
config.logger = nil
10+
config.logger = false
1111
end
12+
Rails.logger = Logger.new(nil)
1213
Rails.env = "production"
1314
TestApp.initialize!
1415
end

spec/raven/logger_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
allow(Raven.configuration).to receive(:logger) { nil }
77
end
88

9-
it 'should not error' do
10-
subject.fatal 'fatalmsg'
11-
subject.error 'errormsg'
12-
subject.warn 'warnmsg'
13-
subject.info 'infomsg'
14-
subject.debug 'debugmsg'
9+
it 'logs to stdout' do
10+
expect { subject.fatal 'fatalmsg' }.to output.to_stdout_from_any_process
1511
end
1612
end
1713

spec/support/test_rails_app/app.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# require "rails/test_unit/railtie"
1111
require 'raven/integrations/rails'
1212

13+
ActiveSupport::Deprecation.silenced = true
14+
1315
class TestApp < Rails::Application
1416
config.secret_key_base = "test"
1517

@@ -18,9 +20,6 @@ class TestApp < Rails::Application
1820
config.cache_classes = true
1921
config.serve_static_files = false
2022

21-
config.log_level = :error
22-
config.logger = Logger.new(STDOUT)
23-
2423
routes.append do
2524
get "/exception", :to => "hello#exception"
2625
root :to => "hello#world"

0 commit comments

Comments
 (0)