Most Spec tests fail if using fail('some error') to test with and_raise(Puppet::Error, /some error/)

7 views
Skip to first unread message

James Perry

unread,
Jul 26, 2017, 2:59:12 PM7/26/17
to Puppet Developers
Can anyone assist my confusion on how to use is_expected.to compile.and_raise(Puppet::Error, /some error/)? 

I have a class where I have fail('some error') and it is only calls class ABC if parameters A=1, B=2, C=3, which I am using to test this functionality out. 

If I have fail('some error') in class ABC, then all the RSPEC tests, but ones where classes aren't included, all fail. If I comment it out all of my tests pass but the one where I had compile.and_raise(/some error/).  

What is the proper way to cause a failure condition to be tested / verified in RSPEC? Am I failing the wrong way? 

Also why would this break the majority of the tests just by having fail in a child class? 

Thanks for everyone's continuing help here. 

Ryan Whitehurst

unread,
Jul 26, 2017, 3:11:30 PM7/26/17
to puppe...@googlegroups.com
If I'm understanding you correctly, rspec is doing what it should and pointing out that your code isn't working as expected. If your code calls fail(), then the catalog fails to compile. The only appropriate rspec matcher in that case is and_raise_error. Any other test is going to fail because there's no catalog to check.

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/bfb280a9-b6a8-4725-817f-75385d785d1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages