summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/monkey_patches.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/util/monkey_patches.rb')
-rw-r--r--lib/puppet/util/monkey_patches.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb
index 6b5af8350..85854a04c 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -48,3 +48,21 @@ if RUBY_VERSION == '1.8.7'
end
end
+class Object
+ # The following code allows callers to make assertions that are only
+ # checked when the environment variable PUPPET_ENABLE_ASSERTIONS is
+ # set to a non-empty string. For example:
+ #
+ # assert_that { condition }
+ # assert_that(message) { condition }
+ if ENV["PUPPET_ENABLE_ASSERTIONS"].to_s != ''
+ def assert_that(message = nil)
+ unless yield
+ raise Exception.new("Assertion failure: #{message}")
+ end
+ end
+ else
+ def assert_that(message = nil)
+ end
+ end
+end