diff options
Diffstat (limited to 'spec/support/shared/unit/provider')
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 24 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/useradd_based_user_provider.rb | 46 |
2 files changed, 35 insertions, 35 deletions
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index d508e76b24..a7c7af92f6 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -258,11 +258,11 @@ shared_examples_for Chef::Provider::File do allow(ChefConfig).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file - stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) + stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000) resource_real_path = File.realpath(resource.path) expect(File).to receive(:stat).with(resource_real_path).at_least(:once).and_return(stat_struct) - allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) - allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) + allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", name: "wheel")) + allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", name: "root")) end context "when the new_resource does not specify any state" do @@ -383,11 +383,11 @@ shared_examples_for Chef::Provider::File do allow(ChefConfig).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file - stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) + stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000) resource_real_path = File.realpath(resource.path) allow(File).to receive(:stat).with(resource_real_path).and_return(stat_struct) - allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) - allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) + allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", name: "wheel")) + allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", name: "root")) provider.send(:load_resource_attributes_from_file, resource) end @@ -460,7 +460,7 @@ shared_examples_for Chef::Provider::File do before { setup_normal_file } let(:tempfile) do - t = double("Tempfile", :path => "/tmp/foo-bar-baz", :closed? => true) + t = double("Tempfile", path: "/tmp/foo-bar-baz", closed?: true) allow(content).to receive(:tempfile).and_return(t) t end @@ -515,7 +515,7 @@ shared_examples_for Chef::Provider::File do before do setup_normal_file provider.load_current_resource - tempfile = double("Tempfile", :path => "/tmp/foo-bar-baz") + tempfile = double("Tempfile", path: "/tmp/foo-bar-baz") allow(content).to receive(:tempfile).and_return(tempfile) expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(true) expect(tempfile).to receive(:close).once @@ -528,8 +528,8 @@ shared_examples_for Chef::Provider::File do let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" } before do allow(provider).to receive(:contents_changed?).and_return(true) - diff = double("Diff", :for_output => ["+++", "---", "+foo", "-bar"], - :for_reporting => diff_for_reporting ) + diff = double("Diff", for_output: ["+++", "---", "+foo", "-bar"], + for_reporting: diff_for_reporting ) allow(diff).to receive(:diff).with(resource_path, tempfile_path).and_return(true) expect(provider).to receive(:diff).at_least(:once).and_return(diff) expect(provider).to receive(:checksum).with(tempfile_path).and_return(tempfile_sha256) @@ -592,13 +592,13 @@ shared_examples_for Chef::Provider::File do end it "raises an exception when the content object returns a tempfile with a nil path" do - tempfile = double("Tempfile", :path => nil) + tempfile = double("Tempfile", path: nil) expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) expect { provider.send(:do_contents_changes) }.to raise_error(RuntimeError) end it "raises an exception when the content object returns a tempfile that does not exist" do - tempfile = double("Tempfile", :path => "/tmp/foo-bar-baz") + tempfile = double("Tempfile", path: "/tmp/foo-bar-baz") expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false) expect { provider.send(:do_contents_changes) }.to raise_error(RuntimeError) diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index caa76e4ad6..a30f543e72 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -68,8 +68,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management" do - allow(@new_resource).to receive(:supports).and_return({ :manage_home => false, - :non_unique => false }) + allow(@new_resource).to receive(:supports).and_return({ manage_home: false, + non_unique: false }) allow(@new_resource).to receive(attribute).and_return("hola") expect(provider.universal_options).to eql([option, "hola"]) end @@ -257,7 +257,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when checking the lock" do # lazy initialize so we can modify stdout and stderr strings let(:passwd_s_status) do - double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => @stdout, :stderr => @stderr, :error! => nil) + double("Mixlib::ShellOut command", exitstatus: 0, stdout: @stdout, stderr: @stderr, error!: nil) end before(:each) do @@ -266,57 +266,57 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option # :nil_object => true, # :username => "adam" # ) - #provider = Chef::Provider::User::Useradd.new(@node, @new_resource) + # provider = Chef::Provider::User::Useradd.new(@node, @new_resource) @stdout = "root P 09/02/2008 0 99999 7 -1" @stderr = "" end it "should return false if status begins with P" do - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end it "should return false if status begins with N" do @stdout = "root N" - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end it "should return true if status begins with L" do @stdout = "root L" - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(true) end it "should raise a ShellCommandFailed exception if passwd -S exits with something other than 0 or 1" do expect(passwd_s_status).to receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed) - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect { provider.check_lock }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end it "should raise an error if the output isn't parsable" do expect(passwd_s_status).to receive(:stdout).and_return("") expect(passwd_s_status).to receive(:stderr).and_return("") - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) end context "when in why run mode" do before do - passwd_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n") - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). - and_return(passwd_status) + passwd_status = double("Mixlib::ShellOut command", exitstatus: 0, stdout: "", stderr: "passwd: user 'chef-test' does not exist\n") + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_status) # ubuntu returns 252 on user-does-not-exist so will raise if #error! is called or if # shell_out! is used allow(passwd_status).to receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed) |