Sha256: eb7d99a6411e666756cb1a823392c5c0e9841f017e1061e1de155e49d3630ef9

Contents?: true

Size: 1008 Bytes

Versions: 18

Compression:

Stored size: 1008 Bytes

Contents

# makes Chef think it's running on a certain platform..useful for unit testing
# platform-specific functionality.
#
# If a block is given yields to the block with +RUBY_PLATFORM+ set to
# 'i386-mingw32' (windows) or 'x86_64-darwin11.2.0' (unix).  Usueful for
# testing code that mixes in platform specific modules like +Chef::Mixin::Securable+
# or +Chef::FileAccessControl+
def platform_mock(platform = :unix, &block)
  allow(Chef::Platform).to receive(:windows?).and_return(platform == :windows ? true : false)
  ENV['SYSTEMDRIVE'] = (platform == :windows ? 'C:' : nil)

  if platform == :windows
    Chef::Config.set_defaults_for_windows
  else
    Chef::Config.set_defaults_for_nix
  end

  if block_given?
    mock_constants({"RUBY_PLATFORM" => (platform == :windows ? 'i386-mingw32' : 'x86_64-darwin11.2.0'),
                    "File::PATH_SEPARATOR" => (platform == :windows ? ";" : ":"),
                    "File::ALT_SEPARATOR" => (platform == :windows ? "\\" : nil) }) do
yield
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chef-12.3.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.3.0 spec/support/mock/platform.rb
chef-12.3.0.rc.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.3.0.rc.0 spec/support/mock/platform.rb
chef-12.2.1-x86-mingw32 spec/support/mock/platform.rb
chef-12.2.1 spec/support/mock/platform.rb
chef-12.2.0.rc.2-x86-mingw32 spec/support/mock/platform.rb
chef-12.2.0.rc.2 spec/support/mock/platform.rb
chef-12.2.0.rc.1-x86-mingw32 spec/support/mock/platform.rb
chef-12.2.0.rc.1 spec/support/mock/platform.rb
chef-12.1.2 spec/support/mock/platform.rb
chef-12.1.2-x86-mingw32 spec/support/mock/platform.rb
chef-12.1.1-x86-mingw32 spec/support/mock/platform.rb
chef-12.1.1 spec/support/mock/platform.rb
chef-12.1.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.1.0 spec/support/mock/platform.rb
chef-12.1.0.rc.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.1.0.rc.0 spec/support/mock/platform.rb