Rails:在向CSS添加资源后,Cucumber测试(使用JS)失败

时间:2015-04-06 19:43:00

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

我对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中删除了除一个文件以外的所有文件,也会发生这种情况。此外,应用程序报告没有404s,字体在开发环境中工作。 这是应用中唯一的资源!

我正在使用:

  • Rails 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

1 个答案:

答案 0 :(得分:0)

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

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")

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