5

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.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • 2
    The way to phrase it is that capybara with the Rack::Test driver (the default) does not run Javascript, while capybara with the webkit driver does run Javascript. That said, I don't know why your tests aren't failing. See if you can think of what in your code or configuration you can add to your question to allow others to help. – Dave Schweisguth May 03 '14 at 06:00
  • Show us your `features/support/env.rb`. As I read your question now, you always use capybara-webkit, and it will just execute javascript perfectly fine. – nathanvda Jun 02 '14 at 22:20

1 Answers1

2

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.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
  • thanks. this might help. however i'm stuck in the process of swiching to poltergeist, maybe you can help there too: http://stackoverflow.com/questions/24004130/ – John Bachir Jun 02 '14 at 22:13