~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/util/log/destinations_spec.rb

  • Committer: Benjamin Kerensa
  • Date: 2012-11-21 23:50:52 UTC
  • mfrom: (1.1.30)
  • Revision ID: bkerensa@ubuntu.com-20121121235052-ah7nzabp77sh69gb
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby -S rspec
 
1
#! /usr/bin/env ruby
2
2
require 'spec_helper'
3
3
 
4
4
require 'puppet/util/log'
24
24
 
25
25
 
26
26
describe Puppet::Util::Log.desttypes[:file] do
 
27
  include PuppetSpec::Files
 
28
 
27
29
  before do
28
30
    File.stubs(:open)           # prevent actually creating the file
 
31
    File.stubs(:chown)          # prevent chown on non existing file from failing 
29
32
    @class = Puppet::Util::Log.desttypes[:file]
30
33
  end
31
34
 
32
 
  it "should default to automatically flush log output" do
33
 
    @class.new('/tmp/log').autoflush.should == true
 
35
  it "should default to autoflush false" do
 
36
    @class.new(tmpfile('log')).autoflush.should == true
34
37
  end
35
38
 
36
39
  describe "when matching" do
106
109
end
107
110
 
108
111
describe Puppet::Util::Log.desttypes[:console] do
109
 
  describe "when color is available" do
110
 
    before :each do
111
 
      subject.stubs(:console_has_color?).returns(true)
112
 
    end
113
 
 
114
 
    it "should support color output" do
115
 
      Puppet[:color] = true
116
 
      subject.colorize(:red, 'version').should == "\e[0;31mversion\e[0m"
117
 
    end
118
 
 
119
 
    it "should withhold color output when not appropriate" do
120
 
      Puppet[:color] = false
121
 
      subject.colorize(:red, 'version').should == "version"
122
 
    end
123
 
 
124
 
    it "should handle multiple overlapping colors in a stack-like way" do
125
 
      Puppet[:color] = true
126
 
      vstring = subject.colorize(:red, 'version')
127
 
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[0;31mversion\e[0;32m)\e[0m"
128
 
    end
129
 
 
130
 
    it "should handle resets in a stack-like way" do
131
 
      Puppet[:color] = true
132
 
      vstring = subject.colorize(:reset, 'version')
133
 
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[mversion\e[0;32m)\e[0m"
134
 
    end
135
 
  end
136
 
end
137
 
 
138
 
describe Puppet::Util::Log.desttypes[:telly_prototype_console] do
139
 
  describe "when color is available" do
140
 
    before :each do
141
 
      subject.stubs(:console_has_color?).returns(true)
142
 
    end
143
 
 
144
 
    it "should support color output" do
145
 
      Puppet[:color] = true
146
 
      subject.colorize(:red, 'version').should == "\e[0;31mversion\e[0m"
147
 
    end
148
 
 
149
 
    it "should withhold color output when not appropriate" do
150
 
      Puppet[:color] = false
151
 
      subject.colorize(:red, 'version').should == "version"
152
 
    end
153
 
 
154
 
    it "should handle multiple overlapping colors in a stack-like way" do
155
 
      Puppet[:color] = true
156
 
      vstring = subject.colorize(:red, 'version')
157
 
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[0;31mversion\e[0;32m)\e[0m"
158
 
    end
159
 
 
160
 
    it "should handle resets in a stack-like way" do
161
 
      Puppet[:color] = true
162
 
      vstring = subject.colorize(:reset, 'version')
163
 
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[mversion\e[0;32m)\e[0m"
 
112
  let (:klass) { Puppet::Util::Log.desttypes[:console] }
 
113
 
 
114
  describe "when color is available" do
 
115
    before :each do
 
116
      subject.stubs(:console_has_color?).returns(true)
 
117
    end
 
118
 
 
119
    it "should support color output" do
 
120
      Puppet[:color] = true
 
121
      subject.colorize(:red, 'version').should == "\e[0;31mversion\e[0m"
 
122
    end
 
123
 
 
124
    it "should withhold color output when not appropriate" do
 
125
      Puppet[:color] = false
 
126
      subject.colorize(:red, 'version').should == "version"
 
127
    end
 
128
 
 
129
    it "should handle multiple overlapping colors in a stack-like way" do
 
130
      Puppet[:color] = true
 
131
      vstring = subject.colorize(:red, 'version')
 
132
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[0;31mversion\e[0;32m)\e[0m"
 
133
    end
 
134
 
 
135
    it "should handle resets in a stack-like way" do
 
136
      Puppet[:color] = true
 
137
      vstring = subject.colorize(:reset, 'version')
 
138
      subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[mversion\e[0;32m)\e[0m"
 
139
    end
 
140
 
 
141
    it "should include the log message's source/context in the output when available" do
 
142
      Puppet[:color] = false
 
143
      $stdout.expects(:puts).with("Info: a hitchhiker: don't panic")
 
144
 
 
145
      msg = Puppet::Util::Log.new(:level => :info, :message => "don't panic", :source => "a hitchhiker")
 
146
      dest = klass.new
 
147
      dest.handle(msg)
164
148
    end
165
149
  end
166
150
end