# # Author:: David Balatero () # 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 'spec_helper' describe Chef::Provider::Package::Macports do before(:each) do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Package.new("zsh") @current_resource = Chef::Resource::Package.new("zsh") @provider = Chef::Provider::Package::Macports.new(@new_resource, @run_context) allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @status = double("Status", :exitstatus => 0) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @pid = 2342 end describe "load_current_resource" do it "should create a current resource with the name of the new_resource" do expect(@provider).to receive(:current_installed_version).and_return(nil) expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource expect(@provider.current_resource.name).to eq("zsh") end it "should create a current resource with the version if the package is installed" do expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") expect(@provider).to receive(:current_installed_version).and_return("4.2.7") @provider.load_current_resource expect(@provider.candidate_version).to eq("4.2.7") end it "should create a current resource with a nil version if the package is not installed" do expect(@provider).to receive(:current_installed_version).and_return(nil) expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource expect(@provider.current_resource.version).to be_nil end it "should set a candidate version if one exists" do expect(@provider).to receive(:current_installed_version).and_return(nil) expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource expect(@provider.candidate_version).to eq("4.2.7") end end describe "current_installed_version" do it "should return the current version if the package is installed" do expect(@stdout).to receive(:read).and_return(<