puppetlabs/puppet-acceptance — pull request #150 by justinstoller (2012-02-20 20:13:28+00:00)
Title: (#12672) add confine method to dsl

Previously if you did not want a test to be executed on a particular node (valuable for filtering out Windows) you had to iterate over all hosts and manually check their properties.

NOTE: This commit builds on pull request #149

This adds a confine method to aid in filtering hosts. It works similarly, but not the same, to the confine method in Puppet.

This method takes as its first parameter either `:to` or `:except` to do either positive or negative filtering of the hosts, it then takes a hash of properties and values that the method will iterate over for the user. Calls to host helpers (like `agents`) will then return only those hosts that have passed the filtering. The confine method will skip the test if no suitable hosts are found (and print the hash it used to filter for clarity). It will also attempt to intellegently use the correct comparison operator depending on whether you pass a string or regex.

```ruby

test_name "Test Task Scheduler"

confine :to, :platform => 'windows'

on agents, "c:\Something\With\Task\Scheduler.exe"

```

or

```ruby

test_name "Test Non-Windows"

confine :except, :platform => 'windows'

on agents, "test/cron"

```

or

```ruby
test_name "Test Deb-based Distros"

confine :to, :platform => /debian|ubuntu/

on agents, "you get the idea"

```

Here is a test run against Puppet FOSS master to ensure backwards compatibility:
https://jenkins.puppetlabs.com/view/CI%20Dev/job/Puppet%20FOSS%20CI%20dev%20--%20Test%20Harness%20ticket%207200%20Xml%20formatting/17/