0

I'm trying to run a set of feature specs in PhantomJS using Poltergeist and Rspec. The specs pass normally, but when I switch jQuery to a CDN they fail. Is there a way to get PhantomJS to load external JavaScript libraries?

Failure/Error: visit root_path
     Capybara::Poltergeist::JavascriptError:
       One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

       ReferenceError: Can't find variable: jQuery
       ReferenceError: Can't find variable: jQuery
           at http://127.0.0.1:60021/assets/application.js:446
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
  • Is the CDN version on HTTPS and do you have a PhantomJS version less than 1.9.8? – Artjom B. Apr 17 '15 at 22:19
  • The assets are all served over HTTPS from CDNJS. However, I'm running PhantomJS 1.9.7. I can upgrade to 1.9.8. Was there a change to the library to fix this during that version bump? – LandonSchropp Apr 18 '15 at 19:58
  • There was a change, but not to PhantomJS, and instead to (nearly) all https servers: [A: PhantomJS failing to open HTTPS site](http://stackoverflow.com/a/26417660/1816580) – Artjom B. Apr 18 '15 at 20:00
  • Great to know. I'll give this a try on Monday when I get back to the office. Thanks! – LandonSchropp Apr 18 '15 at 20:11
  • Unfortunately, that doesn't seem to have solved the issue. Is there a flag I need to flip as well? – LandonSchropp Apr 20 '15 at 17:01

1 Answers1

2

I solved this problem by using protocol-relative URLs to load CDN libraries. This lets me load my libraries over HTTPS in production but the specs can load them using HTTP.

<script src=""//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149