Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Regexp support to with_* matchers and improve error messages #17

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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