From 789cb04d2e8e27cbc5451a7eb5f670a00834de22 Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Tue, 6 Oct 2015 22:44:45 -0700 Subject: put group tests in own context --- spec/functional/resource/user/windows_spec.rb | 36 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/spec/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb index 5aa5ad9862..0e55d8084b 100644 --- a/spec/functional/resource/user/windows_spec.rb +++ b/spec/functional/resource/user/windows_spec.rb @@ -23,7 +23,6 @@ describe Chef::Provider::User::Windows, :windows_only do let(:username) { 'ChefFunctionalTest' } let(:password) { SecureRandom.uuid } - let(:group) {'Guests'} let(:node) do n = Chef::Node.new @@ -36,7 +35,6 @@ describe Chef::Provider::User::Windows, :windows_only do let(:new_resource) do Chef::Resource::User.new(username, run_context).tap do |r| r.provider(Chef::Provider::User::Windows) - r.gid(group) r.password(password) end end @@ -54,7 +52,6 @@ describe Chef::Provider::User::Windows, :windows_only do new_resource.run_action(:create) expect(new_resource).to be_updated_by_last_action expect(shell_out("net user #{username}").exitstatus).to eq(0) - expect(shell_out("net localgroup \"#{group}\"").stdout).to match(/^#{username}\r$/) end it 'reports no changes if there are no changes needed' do @@ -70,11 +67,34 @@ describe Chef::Provider::User::Windows, :windows_only do expect(new_resource).to be_updated_by_last_action end - it 'allows changing the group' do - new_resource.run_action(:create) - new_resource.gid('Power Users') - new_resource.run_action(:create) - expect(shell_out("net localgroup \"Power Users\"").stdout).to match(/^#{username}\r$/) + context 'adding to a group' do + let(:group) {'Guests'} + let(:new_resource) do + Chef::Resource::User.new(username, run_context).tap do |r| + r.provider(Chef::Provider::User::Windows) + r.gid(group) + r.password(password) + end + end + + it 'adds to a group when a group is given' do + new_resource.run_action(:create) + expect(new_resource).to be_updated_by_last_action + expect(shell_out("net localgroup \"#{group}\"").stdout).to match(/^#{username}\r$/) + end + + it 'reports no changes if there are no changes needed' do + new_resource.run_action(:create) + new_resource.run_action(:create) + expect(new_resource).not_to be_updated_by_last_action + end + + it 'allows changing the group' do + new_resource.run_action(:create) + new_resource.gid('Power Users') + new_resource.run_action(:create) + expect(shell_out("net localgroup \"Power Users\"").stdout).to match(/^#{username}\r$/) + end end end -- cgit v1.2.1