Skip to content

Commit

Permalink
Merge pull request #17 from jeffmccune/feature/master/improve_matcher…
Browse files Browse the repository at this point in the history
…_error_message

Add Regexp support to with_* matchers and improve error messages
  • Loading branch information
Jeff McCune committed Dec 29, 2011
2 parents c73f8ce + 3b34a50 commit 8d2e3e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/rspec-puppet/matchers/create_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ def matches?(catalogue)
if resource.nil?
ret = false
else
rsrc_hsh = resource.to_hash
if @expected_params
@expected_params.each do |name, value|
unless resource.send(:parameters)[name.to_sym].to_s == value.to_s
ret = false
(@errors ||= []) << "#{name.to_s} set to `#{value.inspect}`"
if value.kind_of?(Regexp) then
unless rsrc_hsh[name.to_sym].to_s =~ value
ret = false
(@errors ||= []) << "#{name.to_s} matching `#{value.inspect}` but its value of `#{rsrc_hsh[name.to_sym].inspect}` does not"
end
else
unless rsrc_hsh[name.to_sym].to_s == value.to_s
ret = false
(@errors ||= []) << "#{name.to_s} set to `#{value.inspect}` but it is set to `#{rsrc_hsh[name.to_sym].inspect}` in the catalogue"
end
end
end
end
Expand Down Expand Up @@ -71,7 +79,7 @@ def referenced_type(type)
end

def errors
@errors.nil? ? "" : " with #{@errors.join(', ')}"
@errors.nil? ? "" : " with #{@errors.join(', and parameter ')}"
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/classes/boolean_regexp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe 'boolean' do
let(:title) { 'bool.testing' }
let(:params) { { :bool => false } }
let(:message_re) { /bool is false/ }

it { should create_notify("bool testing").with_message(message_re) }
it { should_not create_notify("bool testing").with_message(/true/) }
end

0 comments on commit 8d2e3e6

Please sign in to comment.