【问题标题】:Rails: Cucumber tests (with JS) failing after adding assets to CSSRails:向 CSS 添加资产后,黄瓜测试(使用 JS)失败
【发布时间】:2015-04-06 19:43:00
【问题描述】:

我对 Rails 很陌生,所以这对我来说有点神秘。

我已将一些字体文件添加到 app/assets/fonts 并使用 asset-url 帮助器将它们包含在 SCSS 文件中。但是我现在收到类似于以下内容的错误:

No route matches assets/9df317a3-a79e-422e-b4e2-35ccd29cd5b7 (ActionController::RoutingError)

(注意缺少的文件扩展名?)

在我的 Cucumber 测试中,但在带有 @javascript 标志的测试中。我尝试了以下方法:

RAILS_ENV=test rake assets:precompile

并且此线程中的修复无效:

Capybara tests with :js=>true... Routing Error: No route matches [GET] "/assets"

该线程表明某处存在不正确的资产,但即使我从 CSS 中删除了除一个文件之外的所有文件,也会发生这种情况。此外,该应用程序报告没有 404,并且字体在开发环境中工作。 这些是应用中唯一的资产!

我正在使用:

  • 导轨 4
  • 黄瓜
  • 水豚
  • Poltergeist(用于 JS 测试)

CSS:

@font-face{
  font-family:"l baskerville w01_n4";
  src:asset-url("8dc59876-75a4-4e80-bd1a-735d5f043beb.eot?#iefix")format("eot")
}
etc...

(文件由 fonts.com 提供 [因此文件名可怕])

环境/test.rb:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Do not eager load code on boot. This avoids loading your whole application
  # just for the purpose of running a single test. If you are using a tool that
  # preloads Rails for running tests, you may have to set it to true.
  config.eager_load = false

  # Configure static file server for tests with Cache-Control for performance.
  config.serve_static_files   = true
  config.static_cache_control = 'public, max-age=3600'

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates.
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment.
  config.action_controller.allow_forgery_protection = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Randomize the order test cases are executed.
  config.active_support.test_order = :random

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

任何帮助将不胜感激,我猜这是测试和生产环境中资产管道的问题。但我不知道从哪里开始。

谢谢,

LM

【问题讨论】:

    标签: ruby-on-rails cucumber capybara asset-pipeline poltergeist


    【解决方案1】:

    原来答案是一个简单的语法错误:

    src: asset-url("8dc59876-75a4-4e80-bd1a-735d5f043beb.eot?#iefix")format("eot")

    应该是:

    src: font-url(url("8dc59876-75a4-4e80-bd1a-735d5f043beb.eot?#iefix")) format("eot")

    希望这对像我这样的其他新手有用。

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 2017-09-23
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多