spec/beaker/dsl/helpers_spec.rb in beaker-1.0.0 vs spec/beaker/dsl/helpers_spec.rb in beaker-1.0.1.pre

- old
+ new

@@ -522,10 +522,11 @@ let(:puppet_path) { '/puppet/path' } def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created subject.instance_variable_set(:@path, test_case_path) host.stub(:tmpdir).and_return(tmpdir_path) + host.stub(:file_exist?).and_return(true) end before do stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created host.stub(:[]).and_return(puppet_path) @@ -533,10 +534,17 @@ it "raises an ArgumentError if you try to submit a String instead of a Hash of options" do expect { subject.with_puppet_running_on(host, '--foo --bar') }.to raise_error(ArgumentError, /conf_opts must be a Hash. You provided a String: '--foo --bar'/) end + it 'raises the early_exception if backup_the_file fails' do + subject.should_receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed')) + expect { + subject.with_puppet_running_on(host, {}) + }.to raise_error(RuntimeError, /puppet conf backup failed/) + end + describe "with valid arguments" do before do Tempfile.should_receive(:open).with('beaker') end @@ -621,10 +629,16 @@ it 'restores puppet.conf' do subject.with_puppet_running_on(host, {}) expect(host).to execute_commands_matching(/cat '#{backup_location}' > '#{original_location}'/).once end + + it "doesn't restore a non-existent file" do + subject.stub(:backup_the_file) + subject.with_puppet_running_on(host, {}) + expect(host).to execute_commands_matching(/rm -f '#{original_location}'/) + end end describe 'handling failures' do before do subject.should_receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.')) @@ -660,6 +674,25 @@ subject.with_puppet_running( {:opt => 'value'}, '/dir' ) end end + + describe '#fact_on' do + it 'retreives a fact on host(s)' do + subject.should_receive(:facter).with('osfamily',{}).once + subject.should_receive(:on).and_return(result) + + subject.fact_on('host','osfamily') + end + end + + describe '#fact' do + it 'delegates to #fact_on with the default host' do + subject.stub(:hosts).and_return(hosts) + subject.should_receive(:fact_on).with(master,"osfamily",{}).once + + subject.fact('osfamily') + end + end + end