summaryrefslogtreecommitdiff
path: root/spec/mixlib/authentication/mixlib_log_missing_spec.rb
blob: 4b12b123759b4f1c90f6abfed997f3c8041caaa0 (plain)
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
describe "Mixlib::Authentication::Log" do
  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") }

      load "mixlib/authentication.rb"
    end

    after do
      $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