[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Daniel Pittman daniel at puppetlabs.com
Tue May 10 08:17:57 UTC 2011


The following commit has been merged in the experimental branch:
commit 96195c1dc2fea6262523fcc1726c6dfd7fea274a
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Fri Apr 22 14:08:59 2011 -0700

    maint: add an "exit was called" matcher for rspec.
    
    We have a bunch of places that want to test if exit was called in a block of
    code or not, which we did in a whole pile of ad-hoc ways.  Instead, better to
    have a custom matcher that tests specifically for the correct exit exception
    being thrown, and the right error code in it.
    
    Reviewed-By: Jesse Wolf <jesse at puppetlabs.com>

diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 01ffabc..1dcf3c2 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -80,3 +80,25 @@ RSpec::Matchers.define :have_matching_element do |expected|
     actual.any? { |item| item =~ expected }
   end
 end
+
+RSpec::Matchers.define :exit_with do |expected|
+  actual = nil
+  match do |block|
+    begin
+      block.call
+    rescue SystemExit => e
+      actual = e.status
+    end
+    actual and actual == expected
+  end
+  failure_message_for_should do |block|
+    "expected exit with code #{expected} but " +
+      (actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
+  end
+  failure_message_for_should_not do |block|
+    "expected that exit would not be called with #{expected}"
+  end
+  description do
+    "expect exit with #{expected}"
+  end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list