Skip to content

Commit 63335e2

Browse files
Merge pull request #309 from chambersmp/feature_unix_rspec_support
Add support for unit testing via Unix OS
2 parents fec0326 + 82fd9ca commit 63335e2

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,10 @@ def remove_secret_identifiers(text)
10761076
def ps_manager
10771077
debug_output = Puppet::Util::Log.level == :debug
10781078
# TODO: Allow you to specify an alternate path, either to pwsh generally or a specific pwsh path.
1079-
Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args, debug: debug_output)
1079+
if Pwsh::Util.on_windows?
1080+
Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args, debug: debug_output)
1081+
else
1082+
Pwsh::Manager.instance(Pwsh::Manager.pwsh_path, Pwsh::Manager.pwsh_args, debug: debug_output)
1083+
end
10801084
end
10811085
end

lib/pwsh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def self.pwsh_path(additional_paths = [])
380380
pwsh_paths << File.join(path, 'pwsh.exe') if File.exist?(File.join(path, 'pwsh.exe'))
381381
end
382382
else
383-
search_paths.split(File::PATH_SEPARATOR).each do |path|
383+
search_paths.split(':').each do |path|
384384
pwsh_paths << File.join(path, 'pwsh') if File.exist?(File.join(path, 'pwsh'))
385385
end
386386
end

lib/pwsh/util.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module Util
77
module_function
88

99
# Verifies whether or not the current context is running on a Windows node.
10+
# Implementation copied from `facets`: https://github.com/rubyworks/facets/blob/main/lib/standard/facets/rbconfig.rb
1011
#
1112
# @return [Bool] true if on windows
1213
def on_windows?
13-
# Ruby only sets File::ALT_SEPARATOR on Windows and the Ruby standard
14-
# library uses that to test what platform it's on.
15-
!!File::ALT_SEPARATOR
14+
host_os = RbConfig::CONFIG['host_os']
15+
!!(host_os =~ /mswin|mingw/)
1616
end
1717

1818
# Verify paths specified are valid directories which exist.

spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,21 +2110,44 @@
21102110
end
21112111

21122112
describe '.ps_manager' do
2113-
before do
2114-
allow(Pwsh::Manager).to receive(:powershell_path).and_return('pwsh')
2115-
allow(Pwsh::Manager).to receive(:powershell_args).and_return('args')
2116-
end
2113+
describe '.ps_manager on non-Windows' do
2114+
before do
2115+
allow(Pwsh::Util).to receive(:on_windows?).and_return(false)
2116+
allow(Pwsh::Manager).to receive(:pwsh_path).and_return('pwsh')
2117+
allow(Pwsh::Manager).to receive(:pwsh_args).and_return('args')
2118+
end
21172119

2118-
it 'Initializes an instance of the Pwsh::Manager' do
2119-
expect(Puppet::Util::Log).to receive(:level).and_return(:normal)
2120-
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false)
2121-
expect { provider.ps_manager }.not_to raise_error
2120+
it 'Initializes an instance of the Pwsh::Manager' do
2121+
expect(Puppet::Util::Log).to receive(:level).and_return(:normal)
2122+
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false)
2123+
expect { provider.ps_manager }.not_to raise_error
2124+
end
2125+
2126+
it 'passes debug as true if Puppet::Util::Log.level is debug' do
2127+
expect(Puppet::Util::Log).to receive(:level).and_return(:debug)
2128+
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true)
2129+
expect { provider.ps_manager }.not_to raise_error
2130+
end
21222131
end
21232132

2124-
it 'passes debug as true if Puppet::Util::Log.level is debug' do
2125-
expect(Puppet::Util::Log).to receive(:level).and_return(:debug)
2126-
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true)
2127-
expect { provider.ps_manager }.not_to raise_error
2133+
describe '.ps_manager on Windows' do
2134+
before do
2135+
allow(Pwsh::Util).to receive(:on_windows?).and_return(true)
2136+
allow(Pwsh::Manager).to receive(:powershell_path).and_return('pwsh')
2137+
allow(Pwsh::Manager).to receive(:powershell_args).and_return('args')
2138+
end
2139+
2140+
it 'Initializes an instance of the Pwsh::Manager' do
2141+
expect(Puppet::Util::Log).to receive(:level).and_return(:normal)
2142+
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false)
2143+
expect { provider.ps_manager }.not_to raise_error
2144+
end
2145+
2146+
it 'passes debug as true if Puppet::Util::Log.level is debug' do
2147+
expect(Puppet::Util::Log).to receive(:level).and_return(:debug)
2148+
expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true)
2149+
expect { provider.ps_manager }.not_to raise_error
2150+
end
21282151
end
21292152
end
21302153
end

0 commit comments

Comments
 (0)