Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a failure message for assert in Rspec/Capybara

Tags:

rspec

capybara

In my rspec integration tests, when I have an assertion such as:

assert page.has_content? some_value

if the assertion fails, it displays:

MiniTest::Assertion: 
Failed assertion, no message given

The minitest docs say "All assertion methods accept a msg which is printed if the assertion fails" but I cannot find any examples of HOW to specify the message. These are NOT valid syntax:

assert("custom fail msg") page.has_content? some_value

assert page.has_content? some_value, "custom fail msg"
like image 594
jpw Avatar asked Dec 12 '12 19:12

jpw


1 Answers

Try:

assert page.has_content?(some_value), "custom fail msg"

Assuming I have reproduced your error properly, the issue with your second attempt is that Ruby thinks that "custom fail msg" is a parameter of the page.has_content? rather than the assert. Adding the brackets around the paramaters for the page.has_content? should resolve the issue.

like image 153
Justin Ko Avatar answered Nov 04 '22 23:11

Justin Ko