forked from test-kitchen/test-kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kitchen_spec.rb
111 lines (87 loc) · 2.97 KB
/
kitchen_spec.rb
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
#
# Author:: Fletcher Nichol (<[email protected]>)
#
# Copyright (C) 2014, Fletcher Nichol
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative "spec_helper"
require "kitchen"
describe "Kitchen" do
let(:stdout) { StringIO.new }
before do
FakeFS.activate!
FileUtils.mkdir_p(Dir.pwd)
stdout.stubs(:tty?).returns(true)
@orig_stdout = $stdout
$stdout = stdout
end
after do
$stdout = @orig_stdout
FakeFS.deactivate!
FakeFS::FileSystem.clear
end
describe "defaults" do
it "sets DEFAULT_LOG_LEVEL to :info" do
Kitchen::DEFAULT_LOG_LEVEL.must_equal :info
end
it "sets DEFAULT_TEST_DIR to test/integration, which is frozen" do
Kitchen::DEFAULT_TEST_DIR.must_equal "test/integration"
Kitchen::DEFAULT_TEST_DIR.frozen?.must_equal true
end
it "sets DEFAULT_LOG_DIR to .kitchen/logs, which is frozen" do
Kitchen::DEFAULT_LOG_DIR.must_equal ".kitchen/logs"
Kitchen::DEFAULT_LOG_DIR.frozen?.must_equal true
end
end
it ".tty? returns true if $stdout.tty? is true" do
Kitchen.tty?.must_equal true
end
it ".tty? returns flse is $stdout.tty? is false" do
stdout.stubs(:tty?).returns(false)
Kitchen.tty?.must_equal false
end
it ".source_root returns the root path of the gem" do
Kitchen.source_root
.must_equal Pathname.new(File.expand_path("..", __dir__))
end
it ".default_logger is a Kitchen::Logger" do
Kitchen.default_logger.must_be_instance_of Kitchen::Logger
end
it ".default_logger returns a $stdout logger" do
Kitchen.default_logger.warn("uhoh")
stdout.string.must_match(/ uhoh$/)
end
it ".default_file_logger is a Kitchen::Logger" do
Kitchen.default_file_logger.must_be_instance_of Kitchen::Logger
end
it ".default_file_logger returns a logger that uses $stdout" do
Kitchen.default_logger.warn("uhoh")
stdout.string.must_match(/ uhoh$/)
end
it ".default_file_logger returns a logger that uses a file" do
Kitchen.default_file_logger.warn("uhoh")
IO.read(File.join(%w{.kitchen logs kitchen.log}))
.must_match(/ -- Kitchen: uhoh$/)
end
it ".default_file_logger accepts a level and log_overwrite" do
l = Kitchen.default_file_logger(:error, false)
l.level.must_equal 3
l.log_overwrite.must_equal false
end
it "sets Kitchen.logger to a Kitchen::Logger" do
Kitchen.default_logger.must_be_instance_of Kitchen::Logger
end
it "sets Kitchen.mutex to a Mutex" do
Kitchen.mutex.must_be_instance_of Mutex
end
end