summaryrefslogtreecommitdiffstats
path: root/test/lib/puppettest
diff options
context:
space:
mode:
authorRein Henrichs <rein@puppetlabs.com>2010-06-23 15:49:53 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitaf8bd77a9ff68552490745ec1d479820b6b58d87 (patch)
treeb84b0604074dab8a2e0226159eac5a60f3590d4b /test/lib/puppettest
parent182c0033dcc1885a42bd0cbb429d278f53ae9480 (diff)
downloadpuppet-af8bd77a9ff68552490745ec1d479820b6b58d87.tar.gz
puppet-af8bd77a9ff68552490745ec1d479820b6b58d87.tar.xz
puppet-af8bd77a9ff68552490745ec1d479820b6b58d87.zip
[#4064] Modify confine to also allow a message and a block containing the test.
This way the test can be evaluated lazily when needed. Adds tests and documentation.
Diffstat (limited to 'test/lib/puppettest')
-rw-r--r--test/lib/puppettest/runnable_test.rb54
1 files changed, 32 insertions, 22 deletions
diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb
index 977dba47a..6fcd9c6dc 100644
--- a/test/lib/puppettest/runnable_test.rb
+++ b/test/lib/puppettest/runnable_test.rb
@@ -1,35 +1,45 @@
# Manage whether a test is runnable.
module PuppetTest
module RunnableTest
- # Confine this test based on specified criteria. The keys of the
- # hash should be the message to use if the test is not suitable,
- # and the values should be either 'true' or 'false'; true values
- # mean the test is suitable.
- def confine(hash)
- @confines ||= {}
- hash.each do |message, result|
- @confines[message] = result
- end
+ # Confine this example group based on specified criteria. This can be
+ # a message and its related test either as a hash or as a single
+ # message argument and a block to be evaluated at the time the confine
+ # is checked.
+ #
+ # Examples:
+ #
+ # confine "Rails is not available" => Puppet.features.rails?
+ #
+ # confine("ActiveRecord 2.1.x") { ::ActiveRecord::VERSION::MAJOR == 2 and ::ActiveRecord::VERSION::MINOR <= 1 }
+ #
+ def confine(hash_or_message, &block)
+ hash = block_given? ? {hash_or_message => block} : hash_or_message
+ confines.update hash
end
- attr_reader :messages
-
- # Evaluate all of our tests to see if any of them are false
- # and thus whether this test is considered not runnable.
+ # Check all confines for a given example group, starting with any
+ # specified in the parent example group. If any confine test is false,
+ # the example group is not runnable (and will be skipped). Note: This
+ # is used directly by Rspec and is not intended for develper use.
+ #
def runnable?
- @messages ||= []
- if superclass.respond_to?(:runnable?) and ! superclass.runnable?
+ if superclass.respond_to?(:runnable?) and not superclass.runnable?
return false
end
- return false unless @messages.empty?
- return true unless defined? @confines
- @confines.find_all do |message, result|
- ! result
- end.each do |message, result|
- @messages << message
+
+ confines.each do |message, is_runnable|
+ is_runnable = is_runnable.call if is_runnable.respond_to?(:call)
+ messages << message unless is_runnable
end
- return @messages.empty?
+ messages.empty?
end
+
+ def messages; @messages ||= [] end
+
+ private
+
+ def confines; @confines ||= {} end
end
+
end