在Rspec中运行带有外部库的phantomjs

时间:2015-04-17 22:13:36

标签: rspec phantomjs poltergeist

我正在尝试使用Poltergeist和Rspec在PhantomJS中运行一组功能规范。规范通过,但是当我将jQuery切换到CDN时,它们会失败。有没有办法让PhantomJS加载外部JavaScript库?

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

1 个答案:

答案 0 :(得分:2)

我通过使用协议相对URL加载CDN库解决了这个问题。这允许我在生产中通过HTTPS加载我的库,但规范可以使用HTTP加载它们。

<script src=""//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>