rodjek / rspec-puppet

RSpec tests for your Puppet manifests
http://rspec-puppet.com
MIT License
364 stars 203 forks source link

raise_error signature changed with rspec 3.10.0 #810

Closed smarlow closed 3 years ago

smarlow commented 3 years ago

Currently we have tests of the form it { is_expected.to raise_error Puppet::Error }. These worked up until this morning when we started seeing the following errors:

     Failure/Error: it { is_expected.to raise_error Puppet::Error }
     ArgumentError:
       wrong number of arguments (given 1, expected 2)
     # /.../vendor/bundle/gems/rspec-puppet-2.7.10/lib/rspec-puppet/matchers/raise_error.rb:20:in `new'
     # /.../vendor/bundle/gems/rspec-puppet-2.7.10/lib/rspec-puppet/matchers/raise_error.rb:20:in `raise_error'

The method in question is this:

# rspec-puppet/matchers/raise_error.rb
def raise_error(*args, &block)
  RaiseError.new(*args, &block)
end

It appears that rspec just released version 3.10.0, which changes the initialize method on RaiseError to have 2 required parameters (link). This was been done so that the base rspec raise_error matcher can detect an explicit nil passed to the first parameter and raise a warning (link).

Our current workaround is just to explicitly pass both the exception type and message to raise_error, but I would expect to continue to be able to use the original tests.

I'm not sure what a straightforward fix is. You can change the raise_error matcher to pass in args explicitly instead of using a splat which will resolve the error, but rspec 3.10.0 will now start issuing warnings when it receives nil for the first parameter. You could explicitly pass in the new default value (RSpec::Matchers::BuiltIn::RaiseError::UndefinedValue), but that doesn't exist prior to 3.10.0.

DavidS commented 3 years ago

This has been fixed in https://github.com/rodjek/rspec-puppet/commit/bd9f0f53d3adb70eac1af2bead6e5397f25f71c2#diff-225bb60162eb52e6e6555a13d9f882ad5dedbe6fe987a51dabb4c302c882b6de and released as part of 2.8.0