blob: 9ff2aceb6afc929e3b3396ef2f87cbea7e119cb6 (
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
90
|
#
# Author:: Stephen Delano (<stephen@ospcode.com>)
# Author:: Seth Falcon (<seth@ospcode.com>)
# Copyright:: Copyright 2010 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 "spec_helper"
Chef::Knife::EnvironmentFromFile.load_deps
describe Chef::Knife::EnvironmentFromFile do
before(:each) do
allow(ChefConfig).to receive(:windows?) { false }
@knife = Chef::Knife::EnvironmentFromFile.new
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@knife.name_args = [ "spec.rb" ]
@environment = Chef::Environment.new
@environment.name("spec")
@environment.description("runs the unit tests")
@environment.cookbook_versions({"apt" => "= 1.2.3"})
allow(@environment).to receive(:save).and_return true
allow(@knife.loader).to receive(:load_from).and_return @environment
end
describe "run" do
it "loads the environment data from a file and saves it" do
expect(@knife.loader).to receive(:load_from).with("environments", "spec.rb").and_return(@environment)
expect(@environment).to receive(:save)
@knife.run
end
context "when handling multiple environments" do
before(:each) do
@env_apple = @environment.dup
@env_apple.name("apple")
allow(@knife.loader).to receive(:load_from).with("apple.rb").and_return @env_apple
end
it "loads multiple environments if given" do
@knife.name_args = [ "spec.rb", "apple.rb" ]
expect(@environment).to receive(:save).twice
@knife.run
end
it "loads all environments with -a" do
allow(File).to receive(:expand_path).with("./environments/").and_return("/tmp/environments")
allow(Dir).to receive(:glob).with("/tmp/environments/*.{json,rb}").and_return(["spec.rb", "apple.rb"])
@knife.name_args = []
allow(@knife).to receive(:config).and_return({:all => true})
expect(@environment).to receive(:save).twice
@knife.run
end
end
it "should not print the environment" do
expect(@knife).not_to receive(:output)
@knife.run
end
it "should show usage and exit if not filename is provided" do
@knife.name_args = []
expect(@knife.ui).to receive(:fatal)
expect(@knife).to receive(:show_usage)
expect { @knife.run }.to raise_error(SystemExit)
end
describe "with --print-after" do
it "should pretty print the environment, formatted for display" do
@knife.config[:print_after] = true
expect(@knife).to receive(:output)
@knife.run
end
end
end
end
|