JavaScript 未在 Rails 测试环境中加载

标签 javascript ruby-on-rails ruby-on-rails-3 selenium-webdriver capybara

我无法在 Rails 测试环境中的浏览器中加载 Javascript。这对于通过 capybara 进行的 cucumber Selenium 测试来说是有问题的。这是我的 test.rb (据我所知是默认值)

MyApp::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

  # Configure static asset server for tests with Cache-Control for performance
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=3600"

  # Log error messages when you accidentally call methods on nil
  config.whiny_nils = true

  # 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

  # Raise exception on mass assignment protection for Active Record models
  config.active_record.mass_assignment_sanitizer = :strict

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

这会产生一个与所有内容相连的 application.js。我尝试添加 config.assets.debug = true 以便 Assets 不会串联,然后仅有时加载 JavaScript。如果我复制 development.rb 它似乎可以工作,但这似乎并不理想。

谢谢!

最佳答案

事实证明,由于相互依赖性,less-rails-bootstrap 版本 3.0.1 gem 以错误的顺序加载了 twitter/bootstrap。我们从未注意到这是在开发中,因为默认情况下 Rails 不会压缩开发环境中的资源。因此,那些特定的文件没有被加载,但它们并没有阻止我们所有的 javascript 加载,就像它们在测试中一样。

升级到 less-rails-bootstrap 3.0.3,或要求 twitter/bootstrap 的各个组件在 application.js 中按正确的顺序解决了问题。

关于JavaScript 未在 Rails 测试环境中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19567866/

相关文章:

javascript - 带有 classList 的代码在 IE 中不起作用?

ruby-on-rails - 将配置文件模型的某些属性设置为对其他用户公开(可见)或私有(private)(不可见)的最佳方法是什么?

ruby-on-rails - Rails中的development.log文件有什么用

ruby-on-rails - 如何修复 Rails 中的执行过期错误?

javascript - 实现客户端 WebHook 处理程序?

javascript - Karma 错误 : [$injector:modulerr] Failed to instantiate module due to: (Index. html 工作正常)

ruby-on-rails - 设计:密码重置电子邮件中的 edit_password_url 将用户发送到 url/api/v1/

ruby-on-rails - Rails 路由 - :resource_id vs :id

ruby-on-rails - 通过双层has_many关系检索结果集

Javascript - 在新窗口中的 toUpperCase