What’s the proper way to force an RSpec test to fail?
I’m considering 1.should == 2 however there’s probably something better.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
fail/raisewill do the trick (they are aliases of each other).Example
Fails with:
Alternatives
If you are thinking of using
raise/failin a spec, you should consider that there are probably more explicit ways of writing your expectation.Additionally,
raise/faildoesn’t play well withaggregate_failuresbecause the exception short-circuits the block and won’t run any following matchers.Mark a test as pending
If you need to mark a test as pending to make sure you get back to it, you could use the
fail/raise, but you can also usepending.Assert that a block is not called
If you need to ensure a block is not being executed, consider using the
yieldmatchers. For example: