diff options
author | Paul Berry <paul@puppetlabs.com> | 2011-02-23 15:19:41 -0800 |
---|---|---|
committer | Paul Berry <paul@puppetlabs.com> | 2011-02-23 15:19:41 -0800 |
commit | a767eb03e7a01c047020763c0bfe3b500ac5044d (patch) | |
tree | 967c9f7ff9a5d546224584ea0dc06c0596ab8a2d | |
parent | 7898345acef254ced9316e5a90104609ccb16c2e (diff) | |
parent | 23b711954b1c1ba8deb4035503797c2f38a8ce12 (diff) | |
download | puppet-a767eb03e7a01c047020763c0bfe3b500ac5044d.tar.gz puppet-a767eb03e7a01c047020763c0bfe3b500ac5044d.tar.xz puppet-a767eb03e7a01c047020763c0bfe3b500ac5044d.zip |
Merge branch 'maint/2.6.next/assertions' into 2.6.next
* maint/2.6.next/assertions:
Maint: Add an assertion mechanism to Puppet
-rw-r--r-- | lib/puppet/util/monkey_patches.rb | 18 |
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 |