spec/nagios/zfs/zpool_plugin_spec.rb in nagios-zfs-0.1.0 vs spec/nagios/zfs/zpool_plugin_spec.rb in nagios-zfs-0.1.1

- old
+ new

@@ -2,16 +2,24 @@ module Nagios module ZFS describe ZpoolPlugin do let(:plugin) { ZpoolPlugin.new } - let(:argv) { [] } + let(:argv) { %w(--pool tank) } before do ZpoolPlugin.any_instance.stub(:argv).and_return(argv) end + context 'without required arguments' do + let(:argv) { [] } + + it 'raises an error without pool name' do + expect { plugin }.to raise_error(SystemExit) + end + end + describe '#critical?' do it 'returns true when capacity is critical' do plugin.should_receive(:critical_capacity?).and_return(true) expect(plugin.critical?).to be(true) end @@ -102,30 +110,29 @@ end end describe '#config' do %w(-p --pool).each do |opt| - name = 'tank' - context "with #{opt} #{name}" do - let(:argv) { [opt, name] } + context "with #{opt}" do + before { argv << opt << 'tank' } - it { expect(plugin.config[:zpool]).to eq(name) } + it { expect(plugin.config[:zpool]).to eq('tank') } end end %w(-c --critical).each do |opt| threshold = 42 - context "with #{opt} #{threshold}" do - let(:argv) { [opt, threshold.to_s] } + context "with #{opt}" do + before { argv << opt << threshold.to_s } it { expect(plugin.config[:critical]).to eq(threshold) } end end %w(-w --warning).each do |opt| threshold = 42 - context "with #{opt} #{threshold}" do - let(:argv) { [opt, threshold.to_s] } + context "with #{opt}" do + before { argv << opt << threshold.to_s } it { expect(plugin.config[:warning]).to eq(threshold) } end end end