Skip to content

Commit

Permalink
Merge pull request #767 from pirj/pin-rspec-expectations
Browse files Browse the repository at this point in the history
Fix support for `rspec-expectations` 3.8.5+
  • Loading branch information
rodjek committed Oct 7, 2019
2 parents 85a0d71 + 97267a2 commit 6db5fb0
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec-puppet/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 8 additions & 0 deletions lib/rspec-puppet/matchers/allow_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lib/rspec-puppet/matchers/compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/rspec-puppet/matchers/count_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lib/rspec-puppet/matchers/create_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/rspec-puppet/matchers/include_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ module ManifestMatchers
end
end

def supports_block_expectations
true
end

def supports_value_expectations
true
end
end

end
Expand Down
23 changes: 23 additions & 0 deletions lib/rspec-puppet/matchers/raise_error.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/rspec-puppet/matchers/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec-puppet/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module RSpec::Puppet
module Support
include GenericMatchers

@@cache = RSpec::Puppet::Cache.new

def subject
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/matchers/raise_error_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6db5fb0

Please sign in to comment.