Search code examples
ruby-on-railsrspeccapybarabddpoltergeist

How can I write javascript tests that don't timeout or fail randomly with rspec, capybara, and poltergeist?


I have been having problems with my tests timing out and failing randomly. I have been looking around for best practices of how to write robust capybara integration tests but I don't find anything helpful.

Ever since we started writing a bunch of tests our CI server has been failing randomly, making our app look ver unstable, but the tests always (mostly) pass locally.

I want to find out how you and other experienced BDD/TDD gurus handle:

  • How to deal with external javascript and stuff (KissMetrics, Google Analyics, etc) and
  • Debugging and preventing timeout errors that break the build

Any help would be appreciated.


Solution

  • To follow up on this. I appreciated @jonleighton's invitation to file a bug on poltergeist, but the problems that I encountered were related to two separate problems:

    1. Bad/wrong capybara assertions that would timeout because I was not following the suggestions clearly outlined in this post
    2. 3rd party javascripts and things. Basically I had 3rd party javascripts like kissmetrics, google analytics, and even live help chat that would load each time a test was wrong, I eliminated this from happening and my tests got faster and appear to be more stable/consistent.