From 2247df4f6e828d6791a46cb12d4e2df2e0b98dce Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Tue, 29 May 2012 13:55:26 -0700 Subject: Update for new gem version of puppetlabs_spec_helper This updates the Rakefile and spec_helper to use the common versions available in the puppetlabs_spec_helper rubygem branch. This mostly just removes a bunch of duplicated code, but it also gives us more flexibility in how the module is tested in the future. --- spec/lib/puppet_spec/matchers.rb | 87 ---------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 spec/lib/puppet_spec/matchers.rb (limited to 'spec/lib/puppet_spec/matchers.rb') diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb deleted file mode 100644 index 77f5803..0000000 --- a/spec/lib/puppet_spec/matchers.rb +++ /dev/null @@ -1,87 +0,0 @@ -require 'stringio' - -######################################################################## -# Backward compatibility for Jenkins outdated environment. -module RSpec - module Matchers - module BlockAliases - alias_method :to, :should unless method_defined? :to - alias_method :to_not, :should_not unless method_defined? :to_not - alias_method :not_to, :should_not unless method_defined? :not_to - end - end -end - - -######################################################################## -# Custom matchers... -RSpec::Matchers.define :have_matching_element do |expected| - match do |actual| - 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 - - -RSpec::Matchers.define :have_printed do |expected| - match do |block| - $stderr = $stdout = StringIO.new - - begin - block.call - ensure - $stdout.rewind - @actual = $stdout.read - - $stdout = STDOUT - $stderr = STDERR - end - - if @actual then - case expected - when String - @actual.include? expected - when Regexp - expected.match @actual - else - raise ArgumentError, "No idea how to match a #{@actual.class.name}" - end - end - end - - failure_message_for_should do |actual| - if actual.nil? then - "expected #{expected.inspect}, but nothing was printed" - else - "expected #{expected.inspect} to be printed; got:\n#{actual}" - end - end - - description do - "expect #{expected.inspect} to be printed" - end - - diffable -end -- cgit v1.2.3