Error with JavaScript enabled tests (Bootstrap 3, Rails 4, Travis CI)

不打扰是莪最后的温柔 提交于 2019-12-10 14:51:36

问题


I have strange error that appears only in CI environment. This error does not appear in develpment, production or even local test environments.

ActionController::RoutingError: No route matches [GET] "/fonts/bootstrap/glyphicons-halflings-regular.svg"

Full trace can be found here

In development and production enviroments successfull reqest goes to /assets/bootstrap/glyphicons-halflings-regular.woff. There is a difference in /fonts/ - /assets and svg - woff part. All errors generated by JavaScript enabled tests (Poltergeist / PhantomJS driver). Regular Capybara tests are all green. Chrome devtools says that request for font file is generated by jquery.js, not the page or css file.


回答1:


This is related to the bootstrap-sass gem. I'm using version 3.3.4.1 of it with Rails 4.2.

My presenting issue was very similar but slightly different: the same error in CI with 404 for /fonts/bootstrap/glyphicons-halflings-regular.woff but a different path in dev, /fonts/glyphicons....

The solution that worked for me was adding the following line before including the bootstrap JS with SASS:

$icon-font-path: "bootstrap/";
@import 'bootstrap';

My best clue came from the comments on this issue in the gem's tracker: https://github.com/twbs/bootstrap-sass/issues/480#issuecomment-49237119




回答2:


If you have similar setup to us, you installed Bootstrap manually on Rails and had to do some manual CSS style overrides to point the Glyphicon fonts to the right path. (/assets/botostrap... instead of /fonts/bootstrap...). However the original styles are still present in bootstrap.css, and even though they're overridden, it appears that somehow PhantomJS is still detecting and making use of those originals.

In our case, we had to search for all references to glyphicons-halflings in bootstrap.css and change the path to the correct one. After we do so, the routing errors disappear.

Good luck!



来源:https://stackoverflow.com/questions/25227622/error-with-javascript-enabled-tests-bootstrap-3-rails-4-travis-ci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!