rodjek / rspec-puppet

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

be_valid_types doesn't seem to be able to catch exception #785

Closed faxm0dem closed 4 years ago

faxm0dem commented 4 years ago

I'm migrating a unit test for a ruby type from an older rspec version. If I'm not mistaken, the following should be equivalent:

old style

expect { described_type.new(name: 'test', force: 'nope') }.to raise_error(Puppet::Error)

new style

expect {be_valid_type.with_set_attributes({:force => 'nope'})}.to raise_error(Puppet::Error)

However, while the former works as expected (test succeeds), the latter fails with:

     Failure/Error: expect { be_valid_type.with_set_attributes({:force => 'nope'})}.to raise_error
       expected Exception but nothing was raised
rodjek commented 4 years ago

Hi @faxm0dem,

That matcher does raise exceptions on invalid parameter values and is tested here (the fake type being tested can be viewed here). Can you provide a more complete example to reproduce the scenario you're seeing?

faxm0dem commented 4 years ago

you can check travis for the above failure for more details:

https://travis-ci.org/ccin2p3/puppet-cpan/jobs/652374296?utm_medium=notification&utm_source=github_status

faxm0dem commented 4 years ago

I guess I forgot the should statement (sorry, rspec is kind of black magic to me). Thanks for your quick answer which helped me solve the issue !