File: mixlib_log_missing_spec.rb

package info (click to toggle)
ruby-mixlib-authentication 3.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 256 kB
  • sloc: ruby: 1,099; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download
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{trace 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{trace debug info warn error fatal}.each do |level|
      it "forward #{level} to mixlib-log" do
        expect_any_instance_of(Mixlib::Log).to receive(level).with("foo")

        Mixlib::Authentication.logger.send(level, "foo")
      end
    end
  end
end