Debugging feature specs
Debugging feature specs can be a frustrating experience. However, there are a couple of tricks that can make your debugging session a bit better, at least if you’re using
capybara-webkit to run them.
Today, I was debugging a failure with the classic
expected to find text 'my text' in 'this content'.
Checking the interface
As usual, the first step is to add a
save_and_open_page statement to see what’s happening on the page. I remember getting a lot of leverage out of learning
save_and_open_page. Something about being able to see what’s up is super valuable. This is what I saw:
That seemed like a pretty honest error to me. It was trying to find some text inside an empty modal.
Just like you can use
save_and_open_page to see the page, you can use
page.driver.error_messages to check javacript errors inside
capybara-webkit. I usually combine it with rspec expectations, so that the spec will fail if there are any errors. This is as useful as
Unfortunately, that is as far as it goes. There’s no way to see the backtrace.
After some searching I learnt that
Object.assign and other ES6 goodies are not available on capybara-webkit. That code was running inside a React component, that’s why the modal was empty.
I hope using
page.driver.error_messages helps you too!