We were writing some tests to make sure that some elements were showed on the
page only under certain circumstances when we found a seemingly contradictory behaviour of the have_content matcher.
We had an scenario involving loading more content from an ajax request
similar to this:
On our test we were checking that the response was showed on the page:
To verify that we were indeed testing this we tried to fail the test matching the opposite:
but this test passes smoothly. Actually, you can put both opposite
expectations together and the test will pass:
What gave us the clue about what was happening is that changing the order
makes the test fail:
It seems that capybara waits for the request to finish when the
expectation fails but moves along happily if it passes.
To actually test that the new content wasn’t being loaded, we had to
force capybara to wait before evaluating the assertion: