-
-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathlogging_test.rb
More file actions
113 lines (85 loc) · 3.19 KB
/
logging_test.rb
File metadata and controls
113 lines (85 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# frozen_string_literal: true
require_relative 'test_helper'
class LoggingTest < Minitest::Test
describe "Logging" do
before do
RubySaml::Logging.logger = nil
end
after do
RubySaml::Logging.logger = ::TEST_LOGGER
end
describe "given no specific logging setup" do
it "prints to stdout" do
RubySaml::Logging::DEFAULT_LOGGER.expects(:debug).with('hi mom')
RubySaml::Logging.debug('hi mom')
end
end
describe "given a Rails app" do
let(:logger) { mock('Logger') }
before do
::Rails = mock('Rails module')
::Rails.stubs(:logger).returns(logger)
end
after do
Object.instance_eval { remove_const(:Rails) }
end
it "delegates to Rails" do
logger.expects(:debug).with('hi mom')
logger.expects(:info).with('sup?')
RubySaml::Logging.debug('hi mom')
RubySaml::Logging.info('sup?')
end
end
describe "given a specific Logger" do
let(:logger) { mock('Logger') }
before { RubySaml::Logging.logger = logger }
after do
RubySaml::Logging.logger = ::TEST_LOGGER
end
it "delegates to the object" do
logger.expects(:debug).with('hi mom')
logger.expects(:info).with('sup?')
RubySaml::Logging.debug('hi mom')
RubySaml::Logging.info('sup?')
end
end
describe "OneLogin::RubySaml::Logging compatibility" do
it "defines OneLogin::RubySaml::Logging as an alias to RubySaml::Logging" do
assert defined?(OneLogin::RubySaml::Logging),
"Expected OneLogin::RubySaml::Logging to be defined"
assert_equal RubySaml::Logging.object_id,
OneLogin::RubySaml::Logging.object_id,
"Expected OneLogin::RubySaml::Logging to alias RubySaml::Logging"
end
it "shares the same logger instance when set via RubySaml::Logging" do
logger = mock('Logger')
RubySaml::Logging.logger = logger
assert_same logger, OneLogin::RubySaml::Logging.logger
end
it "shares the same logger instance when set via OneLogin::RubySaml::Logging" do
logger = mock('Logger')
OneLogin::RubySaml::Logging.logger = logger
assert_same logger, RubySaml::Logging.logger
end
it "delegates to the configured logger when using the legacy constant" do
logger = mock('Logger')
OneLogin::RubySaml::Logging.logger = logger
logger.expects(:debug).with('hi mom')
logger.expects(:info).with('sup?')
OneLogin::RubySaml::Logging.debug('hi mom')
OneLogin::RubySaml::Logging.info('sup?')
end
it "respects ENV['ruby-saml/testing'] and does not log when set (legacy constant)" do
logger = mock('Logger')
OneLogin::RubySaml::Logging.logger = logger
ENV["ruby-saml/testing"] = "1"
# No expectations on logger; any call would cause Mocha to fail the test.
OneLogin::RubySaml::Logging.debug('hi mom')
OneLogin::RubySaml::Logging.info('sup?')
OneLogin::RubySaml::Logging.warn('hey')
OneLogin::RubySaml::Logging.error('oops')
ENV.delete("ruby-saml/testing")
end
end
end
end