diff --git a/lib/rspec-puppet/matchers.rb b/lib/rspec-puppet/matchers.rb index eb3c307e8..da192546c 100644 --- a/lib/rspec-puppet/matchers.rb +++ b/lib/rspec-puppet/matchers.rb @@ -6,3 +6,4 @@ require 'rspec-puppet/matchers/dynamic_matchers' require 'rspec-puppet/matchers/type_matchers' require 'rspec-puppet/matchers/allow_value' +require 'rspec-puppet/matchers/raise_error' diff --git a/lib/rspec-puppet/matchers/allow_value.rb b/lib/rspec-puppet/matchers/allow_value.rb index f0b727651..06ff56394 100644 --- a/lib/rspec-puppet/matchers/allow_value.rb +++ b/lib/rspec-puppet/matchers/allow_value.rb @@ -34,6 +34,14 @@ def failure_message def failure_message_when_negated "expected that the type alias would not " + description + " but it does" end + + def supports_block_expectations + true + end + + def supports_value_expectations + true + end end def allow_value(*values) diff --git a/lib/rspec-puppet/matchers/compile.rb b/lib/rspec-puppet/matchers/compile.rb index c373a62a0..f1335ad3c 100644 --- a/lib/rspec-puppet/matchers/compile.rb +++ b/lib/rspec-puppet/matchers/compile.rb @@ -78,6 +78,14 @@ def failure_message_when_negated end end + def supports_block_expectations + true + end + + def supports_value_expectations + true + end + private def missing_dependencies? retval = false diff --git a/lib/rspec-puppet/matchers/count_generic.rb b/lib/rspec-puppet/matchers/count_generic.rb index 20ae2efb3..6aa04a1b5 100644 --- a/lib/rspec-puppet/matchers/count_generic.rb +++ b/lib/rspec-puppet/matchers/count_generic.rb @@ -61,6 +61,14 @@ def failure_message_when_negated "expected that the catalogue would not " + description + " but it does" end + def supports_block_expectations + true + end + + def supports_value_expectations + true + end + private def referenced_type(type) diff --git a/lib/rspec-puppet/matchers/create_generic.rb b/lib/rspec-puppet/matchers/create_generic.rb index d8dabc736..beec1fe69 100644 --- a/lib/rspec-puppet/matchers/create_generic.rb +++ b/lib/rspec-puppet/matchers/create_generic.rb @@ -177,6 +177,14 @@ def diffable? true end + def supports_block_expectations + true + end + + def supports_value_expectations + true + end + def expected @errors.map {|e| e.expected if e.respond_to?(:expected)}.compact.join("\n\n") end diff --git a/lib/rspec-puppet/matchers/include_class.rb b/lib/rspec-puppet/matchers/include_class.rb index 8bc7b9f8e..f4095fa70 100644 --- a/lib/rspec-puppet/matchers/include_class.rb +++ b/lib/rspec-puppet/matchers/include_class.rb @@ -22,6 +22,13 @@ module ManifestMatchers end end + def supports_block_expectations + true + end + + def supports_value_expectations + true + end end end diff --git a/lib/rspec-puppet/matchers/raise_error.rb b/lib/rspec-puppet/matchers/raise_error.rb new file mode 100644 index 000000000..bd7d9f356 --- /dev/null +++ b/lib/rspec-puppet/matchers/raise_error.rb @@ -0,0 +1,23 @@ +module RSpec::Puppet + module GenericMatchers + # Due to significant code base depending on the + # + # is_expected.to raise_error Puppet::Error + # + # syntax, and removal of this syntax from RSpec, extend RSpec's built-in + # `raise_error` matcher to accept a value target, e.g. a subject defined + # as a lambda, e.g.: + # + # subject(:catalogue) { lambda { load_catalogue } } + # + class RaiseError < RSpec::Matchers::BuiltIn::RaiseError + def supports_value_expectations? + true + end + end + + def raise_error(*args, &block) + RaiseError.new(*args, &block) + end + end +end diff --git a/lib/rspec-puppet/matchers/run.rb b/lib/rspec-puppet/matchers/run.rb index 5c1552071..53dbd9952 100644 --- a/lib/rspec-puppet/matchers/run.rb +++ b/lib/rspec-puppet/matchers/run.rb @@ -104,6 +104,14 @@ def description end end + def supports_block_expectations + true + end + + def supports_value_expectations + true + end + private def func_name @func_obj.func_name diff --git a/lib/rspec-puppet/support.rb b/lib/rspec-puppet/support.rb index 8287d0b35..986e21da7 100644 --- a/lib/rspec-puppet/support.rb +++ b/lib/rspec-puppet/support.rb @@ -4,6 +4,8 @@ module RSpec::Puppet module Support + include GenericMatchers + @@cache = RSpec::Puppet::Cache.new def subject diff --git a/spec/unit/matchers/raise_error_spec.rb b/spec/unit/matchers/raise_error_spec.rb new file mode 100644 index 000000000..27e2efdff --- /dev/null +++ b/spec/unit/matchers/raise_error_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' +require 'rspec-puppet/support' + +describe RSpec::Puppet::GenericMatchers::RaiseError do + include RSpec::Puppet::GenericMatchers + + context 'with a failing target' do + subject { lambda { fail 'catalogue load failed' } } + + it { should raise_error 'catalogue load failed' } + end + + context 'with a passing target' do + subject { lambda { } } + + it { should_not raise_error } + end +end