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

raise_error signature changed with rspec 3.10.0 #810

Closed
smarlow opened this issue Oct 30, 2020 · 1 comment
Closed

raise_error signature changed with rspec 3.10.0 #810

smarlow opened this issue Oct 30, 2020 · 1 comment
Labels

Comments

@smarlow
Copy link

smarlow commented Oct 30, 2020

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.

gimmyxd pushed a commit to gimmyxd/puppetlabs-puppet_agent that referenced this issue Nov 2, 2020
The latest release of rspec-expecttions changed
`raise_error` and breaks rspec-puppet: rodjek/rspec-puppet#810

Lock `rspec-expectations < 3.10` until the issue is fixed.
gimmyxd pushed a commit to gimmyxd/puppetlabs-puppet_agent that referenced this issue Nov 2, 2020
The latest release of rspec-expecttions changed
`raise_error` and breaks rspec-puppet: rodjek/rspec-puppet#810

Lock `rspec-expectations < 3.10` until the issue is fixed.
@DavidS DavidS added the bug label Jan 25, 2021
@DavidS
Copy link
Collaborator

DavidS commented Jan 25, 2021

This has been fixed in bd9f0f5#diff-225bb60162eb52e6e6555a13d9f882ad5dedbe6fe987a51dabb4c302c882b6de and released as part of 2.8.0

@DavidS DavidS closed this as completed Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants