/
perl_spec.rb
82 lines (74 loc) · 2.59 KB
/
perl_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
#
# Author:: Joshua Timberman(<joshua@opscode.com>)
# Copyright:: Copyright (c) 2009 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# 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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin perl" do
before(:each) do
@ohai = Ohai::System.new
@ohai[:languages] = Mash.new
@ohai.stub!(:require_plugin).and_return(true)
@pid = 2342
@stderr = StringIO.new
@stdout = StringIO.new(<<-OUT)
version='5.8.8';
archname='darwin-thread-multi-2level';
OUT
@stdin = StringIO.new
@status = 0
@ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
])
end
it "should run perl -V:version -V:archname" do
@ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true)
@ohai._require_plugin("perl")
end
it "should iterate over each line of perl command's stdout" do
@stdout.should_receive(:each_line).and_return(true)
@ohai._require_plugin("perl")
end
it "should set languages[:perl][:version]" do
@ohai._require_plugin("perl")
@ohai.languages[:perl][:version].should eql("5.8.8")
end
it "should set languages[:perl][:archname]" do
@ohai._require_plugin("perl")
@ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
end
it "should set languages[:perl] if perl command succeeds" do
@status = 0
@ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
])
@ohai._require_plugin("perl")
@ohai.languages.should have_key(:perl)
end
it "should not set languages[:perl] if perl command fails" do
@status = 1
@ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
])
@ohai._require_plugin("perl")
@ohai.languages.should_not have_key(:perl)
end
end