1+ #
2+ # Author:: Stephen Delano (<stephen@ospcode.com>)
3+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
4+ # License:: Apache License, Version 2.0
5+ #
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
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
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.
17+ #
18+
19+ require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , "spec_helper" ) )
20+
21+ describe Chef ::Knife ::EnvironmentFromFile do
22+ before ( :each ) do
23+ @knife = Chef ::Knife ::EnvironmentFromFile . new
24+ @knife . stub! ( :msg ) . and_return true
25+ @knife . stub! ( :output ) . and_return true
26+ @knife . stub! ( :show_usage ) . and_return true
27+ @knife . name_args = [ "spec.rb" ]
28+
29+ @environment = Chef ::Environment . new
30+ @environment . name ( "spec" )
31+ @environment . description ( "runs the unit tests" )
32+ @environment . cookbook_versions ( { "apt" => "1.2.3" } )
33+ @environment . stub! ( :save ) . and_return true
34+ @knife . stub! ( :load_from_file ) . and_return @environment
35+ end
36+
37+ describe "run" do
38+ it "should load from a file" do
39+ @knife . should_receive ( :load_from_file )
40+ @knife . run
41+ end
42+
43+ it "should save the environment" do
44+ @environment . should_receive ( :save )
45+ @knife . run
46+ end
47+
48+ it "should not print the environment" do
49+ @knife . should_not_receive ( :output )
50+ @knife . run
51+ end
52+
53+ it "should show usage and exit if not filename is provided" do
54+ @knife . name_args = [ ]
55+ @knife . should_receive ( :show_usage )
56+ lambda { @knife . run } . should raise_error ( SystemExit )
57+ end
58+
59+ describe "with --print-after" do
60+ it "should pretty print the environment, formatted for display" do
61+ @knife . config [ :print_after ] = true
62+ @knife . should_receive ( :output )
63+ @knife . run
64+ end
65+ end
66+ end
67+ end
0 commit comments