spec/backend/exec/build_command_spec.rb in specinfra-2.59.0 vs spec/backend/exec/build_command_spec.rb in specinfra-2.59.1

- old
+ new

@@ -1,8 +1,12 @@ require 'spec_helper' describe Specinfra::Backend::Exec do + before :all do + set :backend, :exec + end + describe '#build_command' do context 'with simple command' do it 'should escape spaces' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end @@ -105,17 +109,17 @@ end describe 'os' do before do # clear os information cache - property[:os_by_host] = {} + property[:os] = nil + Specinfra.configuration.instance_variable_set(:@os, nil) end context 'test ubuntu with lsb_release command' do - subject { os } - it do - expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| + before do + allow(Specinfra.backend).to receive(:run_command) do |args| if ['ls /etc/debian_version', 'lsb_release -ir'].include? args double( :run_command_response, :success? => true, :stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n" @@ -124,21 +128,21 @@ double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end + end + subject! { os } + it do + expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test ubuntu with /etc/lsb-release' do before do - property[:os] = nil - end - subject { os } - it do - expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| + allow(Specinfra.backend).to receive(:run_command) do |args| if ['ls /etc/debian_version', 'cat /etc/lsb-release'].include? args double( :run_command_response, :success? => true, :stdout => <<-EOF @@ -152,28 +156,32 @@ double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end + end + subject! { os } + it do + expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test debian (no lsb_release or lsb-release)' do before do - property[:os] = nil - end - subject { os } - it do - expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| + allow(Specinfra.backend).to receive(:run_command) do |args| if args == 'ls /etc/debian_version' double :run_command_response, :success? => true, :stdout => nil elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end + end + subject! { os } + it do + expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'debian', :release => nil, :arch => 'x86_64' }) end end end