diff options
Diffstat (limited to 'spec/mixlib/authentication')
-rw-r--r-- | spec/mixlib/authentication/mixlib_authentication_spec.rb | 3 | ||||
-rw-r--r-- | spec/mixlib/authentication/mixlib_log_missing_spec.rb | 61 |
2 files changed, 62 insertions, 2 deletions
diff --git a/spec/mixlib/authentication/mixlib_authentication_spec.rb b/spec/mixlib/authentication/mixlib_authentication_spec.rb index d0e8071..221e803 100644 --- a/spec/mixlib/authentication/mixlib_authentication_spec.rb +++ b/spec/mixlib/authentication/mixlib_authentication_spec.rb @@ -63,8 +63,7 @@ class MockFile end # Uncomment this to get some more info from the methods we're testing. -#Mixlib::Authentication::Log.logger = Logger.new(STDERR) -#Mixlib::Authentication::Log.level :debug +#Mixlib::Authentication.logger.level = :debug describe "Mixlib::Authentication::SignedHeaderAuth" do diff --git a/spec/mixlib/authentication/mixlib_log_missing_spec.rb b/spec/mixlib/authentication/mixlib_log_missing_spec.rb new file mode 100644 index 0000000..d3a6b4c --- /dev/null +++ b/spec/mixlib/authentication/mixlib_log_missing_spec.rb @@ -0,0 +1,61 @@ +describe "Mixlib::Authentication::Log" do + let(:stdout) { StringIO.new } + + before do + Mixlib::Authentication.send(:remove_const, "DEFAULT_SERVER_API_VERSION") + Mixlib::Authentication.send(:remove_const, "Log") + end + + context "without mixlib-log" do + before do + @mixlib_path = $LOAD_PATH.find { |p| p.match("mixlib-log") } + $LOAD_PATH.reject! { |p| p.match("mixlib-log") } + + @old_std_out = $stdout + $stdout = stdout + + load "mixlib/authentication.rb" + end + + after do + $stdout = @old_std_out + $LOAD_PATH.unshift(@mixlib_path) + end + + it "uses MixlibLogMissing" do + expect(Mixlib::Authentication::Log.singleton_class.included_modules) + .to include(Mixlib::Authentication::NullLogger) + end + + it "default log level is :error" do + expect(Mixlib::Authentication::Log.level).to eq(:error) + end + + %w{debug info warn error fatal}.each do |level| + it "logs at level #{level}" do + expect(Mixlib::Authentication::Log).to receive(level).with("foo") + + Mixlib::Authentication.logger.send(level, "foo") + end + end + end + + context "with mixlib-log" do + before do + load "mixlib/authentication.rb" + end + + it "uses Mixlib::Log" do + expect(Mixlib::Authentication::Log.singleton_class.included_modules) + .to include(Mixlib::Log) + end + + %w{debug info warn error fatal}.each do |level| + it "forward #{level} to mixlib-log" do + expect(Mixlib::Authentication::Log.logger).to receive(level).with("foo") + + Mixlib::Authentication.logger.send(level, "foo") + end + end + end +end |