Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my Javascript-dependent feature specs passing when not in Javascript mode?

I have non-Javascript specs and Javascript feature specs that use capybara/capybara-webkit.

I have some tests that I expected to fail when in non-Javascript mode, but they are passing. I've tried the functionality in my browser with Javascript turned off, and the functionality does indeed not work as expected. But in Capybara, it works.

I've also tried adding js: false to the individual test, to make sure there wasn't something hidden in my config turning it on. The spec still passes.

The selenium gem is not included in my Gemfile.

like image 883
John Bachir Avatar asked Nov 01 '22 01:11

John Bachir


1 Answers

I see two possibilities: your tests are correct but there might be some reason why they pass unexpectedly, or your tests are incorrect and are passing for the wrong reason when you run them in Javascript.

A few suggestions for how to debug that apply to both possibilities:

  • Use a debugger. (If you have, let us know what you learned.)

  • Look at the Rails log from a single run of a spec to see what controller actions are called and in what order.

  • Use save_and_open_page to snapshot your page and see whether your spec should pass on what you're looking at.

Double-check your tests when run with Javascript:

  • Run them with the poltergeist driver instead of the capybara-webkit driver. It gives better error messages than capybara-webkit and can be configured to report Javascript error messages.

  • Use save_screenshot to take an actual screenshot of the page and verify that the spec is not passing for a spurious reason, perhaps because some content is off the screen.

If you want to be sure whether rspec is running Javascript, use ps to see whether there is a capybara-webkit or phantomjs process running.

like image 70
Dave Schweisguth Avatar answered Nov 08 '22 08:11

Dave Schweisguth