summaryrefslogtreecommitdiff
path: root/spec/support/mock/platform.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/mock/platform.rb')
-rw-r--r--spec/support/mock/platform.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/support/mock/platform.rb b/spec/support/mock/platform.rb
new file mode 100644
index 0000000000..78b704ea9b
--- /dev/null
+++ b/spec/support/mock/platform.rb
@@ -0,0 +1,18 @@
+# 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)
+ Chef::Platform.stub!(:windows?).and_return(platform == :windows ? true : false)
+ ENV['SYSTEMDRIVE'] = (platform == :windows ? 'C:' : nil)
+ 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