blob: b0f791f82a1fc3d28a8e63b9509f1eaf5b8d347e (
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
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
|
#!/usr/bin/env ruby
require 'spec_helper'
describe Puppet::Util::Colors do
include Puppet::Util::Colors
let (:message) { 'a message' }
let (:color) { :black }
let (:subject) { self }
describe ".console_color" do
it { should respond_to :console_color }
it "should generate ANSI escape sequences" do
subject.console_color(color, message).should == "\e[0;30m#{message}\e[0m"
end
end
describe ".html_color" do
it { should respond_to :html_color }
it "should generate an HTML span element and style attribute" do
subject.html_color(color, message).should =~ /<span style=\"color: #FFA0A0\">#{message}<\/span>/
end
end
describe ".colorize" do
it { should respond_to :colorize }
context "ansicolor supported" do
before :each do
subject.stubs(:console_has_color?).returns(true)
end
it "should colorize console output" do
Puppet[:color] = true
subject.expects(:console_color).with(color, message)
subject.colorize(:black, message)
end
it "should not colorize unknown color schemes" do
Puppet[:color] = :thisisanunknownscheme
subject.colorize(:black, message).should == message
end
end
context "ansicolor not supported" do
before :each do
subject.stubs(:console_has_color?).returns(false)
end
it "should not colorize console output" do
Puppet[:color] = true
subject.expects(:console_color).never
subject.colorize(:black, message).should == message
end
it "should colorize html output" do
Puppet[:color] = :html
subject.expects(:html_color).with(color, message)
subject.colorize(color, message)
end
end
end
context "on Windows in Ruby 1.x", :if => Puppet.features.microsoft_windows? && RUBY_VERSION =~ /^1./ do
it "should define WideConsole" do
expect(defined?(Puppet::Util::Colors::WideConsole)).to be_true
end
it "should define WideIO" do
expect(defined?(Puppet::Util::Colors::WideIO)).to be_true
end
end
context "on Windows in Ruby 2.x", :if => Puppet.features.microsoft_windows? && RUBY_VERSION =~ /^2./ do
it "should not define WideConsole" do
expect(defined?(Puppet::Util::Colors::WideConsole)).to be_false
end
it "should not define WideIO" do
expect(defined?(Puppet::Util::Colors::WideIO)).to be_false
end
end
end
|