summaryrefslogtreecommitdiff
path: root/spec/unit/provider/mount_spec.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-05-23 10:44:25 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-05-28 16:59:26 -0700
commit46eb9f7523fdce0dda498d8cafa6e2ddb79ed3e6 (patch)
tree683d51f2ad5605099987613adc67d8972bc46b90 /spec/unit/provider/mount_spec.rb
parentf4c275cc812ca25aa9ff7cdbca8d061de76f2b4a (diff)
downloadchef-46eb9f7523fdce0dda498d8cafa6e2ddb79ed3e6.tar.gz
spec file modernization
Diffstat (limited to 'spec/unit/provider/mount_spec.rb')
-rw-r--r--spec/unit/provider/mount_spec.rb172
1 files changed, 92 insertions, 80 deletions
diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb
index 3c3919081e..3f0bbb74bf 100644
--- a/spec/unit/provider/mount_spec.rb
+++ b/spec/unit/provider/mount_spec.rb
@@ -1,6 +1,7 @@
#
-# Author:: Joshua Timberman (<joshua@opscode.com>)
-# Copyright:: Copyright (c) 2008 OpsCode, Inc.
+# Author:: Joshua Timberman (<joshua@getchef.com>)
+# Author:: Lamont Granquist (<lamont@getchef.com>)
+# Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,155 +20,166 @@
require 'spec_helper'
describe Chef::Provider::Mount do
- before(:each) do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
-
- @new_resource = Chef::Resource::Mount.new('/tmp/foo')
- @new_resource.device "/dev/sdz1"
- @new_resource.name "/tmp/foo"
- @new_resource.mount_point "/tmp/foo"
- @new_resource.fstype "ext3"
-
- @current_resource = Chef::Resource::Mount.new('/tmp/foo')
- @current_resource.device "/dev/sdz1"
- @current_resource.name "/tmp/foo"
- @current_resource.mount_point "/tmp/foo"
- @current_resource.fstype "ext3"
-
- @provider = Chef::Provider::Mount.new(@new_resource, @run_context)
- @provider.current_resource = @current_resource
+
+ let(:node) { Chef::Node.new }
+
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+
+ let(:new_resource) do
+ new_resource = Chef::Resource::Mount.new('/tmp/foo')
+ new_resource.device "/dev/sdz1"
+ new_resource.name "/tmp/foo"
+ new_resource.mount_point "/tmp/foo"
+ new_resource.fstype "ext3"
+ new_resource
+ end
+
+ let(:current_resource) do
+ # this abstract superclass has no load_current_resource to call
+ current_resource = Chef::Resource::Mount.new('/tmp/foo')
+ current_resource.device "/dev/sdz1"
+ current_resource.name "/tmp/foo"
+ current_resource.mount_point "/tmp/foo"
+ current_resource.fstype "ext3"
+ current_resource
+ end
+
+ let(:provider) do
+ provider = Chef::Provider::Mount.new(new_resource, run_context)
+ provider.current_resource = current_resource
+ provider
end
describe "when the target state is a mounted filesystem" do
it "should mount the filesystem if it isn't mounted" do
- @current_resource.stub(:mounted).and_return(false)
- @provider.should_receive(:mount_fs).with.and_return(true)
- @provider.run_action(:mount)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(false)
+ expect(provider).to receive(:mount_fs).and_return(true)
+ provider.run_action(:mount)
+ expect(new_resource).to be_updated_by_last_action
end
it "should not mount the filesystem if it is mounted" do
- @current_resource.stub(:mounted).and_return(true)
- @provider.should_not_receive(:mount_fs)
- @provider.run_action(:mount)
- @new_resource.should_not be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(true)
+ expect(provider).not_to receive(:mount_fs)
+ provider.run_action(:mount)
+ expect(new_resource).not_to be_updated_by_last_action
end
end
describe "when the target state is an unmounted filesystem" do
it "should umount the filesystem if it is mounted" do
- @current_resource.stub(:mounted).and_return(true)
- @provider.should_receive(:umount_fs).with.and_return(true)
- @provider.run_action(:umount)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(true)
+ expect(provider).to receive(:umount_fs).and_return(true)
+ provider.run_action(:umount)
+ expect(new_resource).to be_updated_by_last_action
end
it "should not umount the filesystem if it is not mounted" do
- @current_resource.stub(:mounted).and_return(false)
- @provider.should_not_receive(:umount_fs)
- @provider.run_action(:umount)
- @new_resource.should_not be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(false)
+ expect(provider).not_to receive(:umount_fs)
+ provider.run_action(:umount)
+ expect(new_resource).not_to be_updated_by_last_action
end
end
describe "when the filesystem should be remounted and the resource supports remounting" do
before do
- @new_resource.supports[:remount] = true
+ new_resource.supports[:remount] = true
end
it "should remount the filesystem if it is mounted" do
- @current_resource.stub(:mounted).and_return(true)
- @provider.should_receive(:remount_fs).and_return(true)
- @provider.run_action(:remount)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(true)
+ expect(provider).to receive(:remount_fs).and_return(true)
+ provider.run_action(:remount)
+ expect(new_resource).to be_updated_by_last_action
end
it "should not remount the filesystem if it is not mounted" do
- @current_resource.stub(:mounted).and_return(false)
- @provider.should_not_receive(:remount_fs)
- @provider.run_action(:remount)
- @new_resource.should_not be_updated_by_last_action
+ allow(current_resource).to receive(:mounted).and_return(false)
+ expect(provider).not_to receive(:remount_fs)
+ provider.run_action(:remount)
+ expect(new_resource).not_to be_updated_by_last_action
end
end
describe "when the filesystem should be remounted and the resource does not support remounting" do
before do
- @new_resource.supports[:remount] = false
- @current_resource.stub(:mounted).and_return(true)
+ new_resource.supports[:remount] = false
+ allow(current_resource).to receive(:mounted).and_return(true)
end
it "should try a umount/remount of the filesystem" do
- @provider.should_receive(:umount_fs)
- @provider.should_receive(:mount_fs)
- @provider.run_action(:remount)
- @new_resource.should be_updated_by_last_action
+ expect(provider).to receive(:umount_fs)
+ expect(provider).to receive(:mount_fs)
+ provider.run_action(:remount)
+ expect(new_resource).to be_updated_by_last_action
end
end
describe "when enabling the filesystem to be mounted" do
it "should enable the mount if it isn't enable" do
- @current_resource.stub(:enabled).and_return(false)
- @provider.should_not_receive(:mount_options_unchanged?)
- @provider.should_receive(:enable_fs).and_return(true)
- @provider.run_action(:enable)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:enabled).and_return(false)
+ expect(provider).not_to receive(:mount_options_unchanged?)
+ expect(provider).to receive(:enable_fs).and_return(true)
+ provider.run_action(:enable)
+ expect(new_resource).to be_updated_by_last_action
end
it "should enable the mount if it is enabled and mount options have changed" do
- @current_resource.stub(:enabled).and_return(true)
- @provider.should_receive(:mount_options_unchanged?).and_return(false)
- @provider.should_receive(:enable_fs).and_return(true)
- @provider.run_action(:enable)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:enabled).and_return(true)
+ expect(provider).to receive(:mount_options_unchanged?).and_return(false)
+ expect(provider).to receive(:enable_fs).and_return(true)
+ provider.run_action(:enable)
+ expect(new_resource).to be_updated_by_last_action
end
it "should not enable the mount if it is enabled and mount options have not changed" do
- @current_resource.stub(:enabled).and_return(true)
- @provider.should_receive(:mount_options_unchanged?).and_return(true)
- @provider.should_not_receive(:enable_fs)
- @provider.run_action(:enable)
- @new_resource.should_not be_updated_by_last_action
+ allow(current_resource).to receive(:enabled).and_return(true)
+ expect(provider).to receive(:mount_options_unchanged?).and_return(true)
+ expect(provider).not_to receive(:enable_fs)
+ provider.run_action(:enable)
+ expect(new_resource).not_to be_updated_by_last_action
end
end
describe "when the target state is to disable the mount" do
it "should disable the mount if it is enabled" do
- @current_resource.stub(:enabled).and_return(true)
- @provider.should_receive(:disable_fs).with.and_return(true)
- @provider.run_action(:disable)
- @new_resource.should be_updated_by_last_action
+ allow(current_resource).to receive(:enabled).and_return(true)
+ expect(provider).to receive(:disable_fs).and_return(true)
+ provider.run_action(:disable)
+ expect(new_resource).to be_updated_by_last_action
end
it "should not disable the mount if it isn't enabled" do
- @current_resource.stub(:enabled).and_return(false)
- @provider.should_not_receive(:disable_fs)
- @provider.run_action(:disable)
- @new_resource.should_not be_updated_by_last_action
+ allow(current_resource).to receive(:enabled).and_return(false)
+ expect(provider).not_to receive(:disable_fs)
+ provider.run_action(:disable)
+ expect(new_resource).not_to be_updated_by_last_action
end
end
it "should delegates the mount implementation to subclasses" do
- lambda { @provider.mount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect { provider.mount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
it "should delegates the umount implementation to subclasses" do
- lambda { @provider.umount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect { provider.umount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
it "should delegates the remount implementation to subclasses" do
- lambda { @provider.remount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect { provider.remount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
it "should delegates the enable implementation to subclasses" do
- lambda { @provider.enable_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect { provider.enable_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
it "should delegates the disable implementation to subclasses" do
- lambda { @provider.disable_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect { provider.disable_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end