2
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
3
# Copyright:: Copyright (c) 2008 Opscode, Inc.
4
# License:: Apache License, Version 2.0
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
18
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
20
describe Chef::Application, "initialize" do
22
@app = Chef::Application.new
25
it "should create an instance of Chef::Application" do
26
@app.should be_kind_of(Chef::Application)
31
describe Chef::Application, "reconfigure" do
33
@app = Chef::Application.new
34
@app.stub!(:configure_chef).and_return(true)
35
@app.stub!(:configure_logging).and_return(true)
38
it "should configure chef" do
39
@app.should_receive(:configure_chef).and_return(true)
43
it "should configure logging" do
44
@app.should_receive(:configure_logging).and_return(true)
50
describe Chef::Application do
52
@app = Chef::Application.new
57
@app.stub!(:setup_application).and_return(true)
58
@app.stub!(:run_application).and_return(true)
59
@app.stub!(:configure_chef).and_return(true)
60
@app.stub!(:configure_logging).and_return(true)
63
it "should reconfigure the application before running" do
64
@app.should_receive(:reconfigure).and_return(true)
68
it "should setup the application before running it" do
69
@app.should_receive(:setup_application).and_return(true)
73
it "should run the actual application" do
74
@app.should_receive(:run_application).and_return(true)
80
describe Chef::Application, "configure_chef" do
82
@app = Chef::Application.new
83
Chef::Config.stub!(:merge!).and_return(true)
84
@app.stub!(:parse_options).and_return(true)
87
it "should parse the commandline options" do
88
@app.should_receive(:parse_options).and_return(true)
92
describe "when a config_file is present" do
94
@app.config[:config_file] = "/etc/chef/default.rb"
95
File.stub!(:exists?).and_return(true)
96
File.stub!(:readable?).and_return(true)
99
it "should configure chef::config from a file" do
100
Chef::Config.should_receive(:from_file).with("/etc/chef/default.rb")
105
describe "when there is no config_file defined" do
107
@app.config[:config_file] = nil
110
it "should configure chef::config from a file" do
111
Chef::Config.should_not_receive(:from_file).with("/etc/chef/default.rb")
117
it "should merge the local config hash into chef::config" do
118
Chef::Config.should_receive(:merge!).and_return(true)
124
describe Chef::Application, "configure_logging" do
126
@app = Chef::Application.new
127
Chef::Log.stub!(:init)
128
Chef::Log.stub!(:level)
131
it "should initialise the chef logger" do
132
Chef::Log.should_receive(:init).with(Chef::Config[:log_location]).and_return(true)
133
@app.configure_logging
136
it "should initialise the chef logger level" do
137
Chef::Log.should_receive(:level).with(Chef::Config[:log_level]).and_return(true)
138
@app.configure_logging
143
describe Chef::Application, "class method: fatal!" do
145
STDERR.stub!(:puts).with("FATAL: blah").and_return(true)
146
Chef::Log.stub!(:fatal).with("blah").and_return(true)
147
Process.stub!(:exit).and_return(true)
150
it "should log an error message to the logger" do
151
Chef::Log.should_receive(:fatal).with("blah").and_return(true)
152
Chef::Application.fatal! "blah"
155
it "should log an error message on STDERR" do
156
STDERR.should_receive(:puts).with("FATAL: blah").and_return(true)
157
Chef::Application.fatal! "blah"
160
describe "when an exit code is supplied" do
161
it "should exit with the given exit code" do
162
Process.should_receive(:exit).with(-100).and_return(true)
163
Chef::Application.fatal! "blah", -100
167
describe "when an exit code is not supplied" do
168
it "should exit with the default exit code" do
169
Process.should_receive(:exit).with(-1).and_return(true)
170
Chef::Application.fatal! "blah"
176
describe Chef::Application, "setup_application" do
178
@app = Chef::Application.new
181
it "should raise an error" do
182
lambda { @app.setup_application }.should raise_error(Chef::Exceptions::Application)
186
describe Chef::Application, "run_application" do
188
@app = Chef::Application.new
191
it "should raise an error" do
192
lambda { @app.run_application }.should raise_error(Chef::Exceptions::Application)