Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the usage of const_defined? in the WinRM detection helper #406

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/train/platforms/detect/helpers/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def ruby_host_os(regex)
end

def winrm?
Object.const_defined?('Train::Transports::WinRM::Connection') &&
@backend.class == Train::Transports::WinRM::Connection
@backend.class.to_s == 'Train::Transports::WinRM::Connection'
end

def unix_file_contents(path)
Expand Down
12 changes: 11 additions & 1 deletion test/unit/platforms/detect/os_common_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ def initialize
detector.winrm?.must_equal(true)
end

it 'return winrm? false' do
it 'return winrm? false when winrm is loaded' do
require 'train/transports/winrm'
be = mock('Backend')
detector.instance_variable_set(:@backend, be)
detector.winrm?.must_equal(false)
end

it 'return winrm? false when winrm is not loaded' do
require 'train/transports/winrm'
winrm = Train::Transports.send(:remove_const, 'WinRM')
be = mock('Backend')
detector.instance_variable_set(:@backend, be)
detector.winrm?.must_equal(false)
Train::Transports.const_set('WinRM', winrm)
end
end

Expand Down