Rails 3.2.1:在视图中调用未定义的方法会导致测试挂起 30+;秒

发布于 2025-01-03 09:16:48 字数 2832 浏览 1 评论 0原文

我正在将我的应用程序从 3.0.9 升级到 3.2.1(ruby 1.9.3-p0、rvm、bundler),而我尚未找到的一件事就是这个问题。我有一个控制器规范(在规范/控制器中),它为每个示例呈现视图。它呈现的模板可以具有任何未定义的方法(例如在 haml 中调用“-blahblah”),并且它会导致测试挂起超过 30 秒。这是错误:

undefined local variable or method `blahblahblah' for #<#<Class:0x007fa84f76cc90>:0x007fa849c578c8>

我运行了调试器,在尝试记录错误本身时发生了挂起。这发生在 activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb line 22 中。那么这是 Rails 的错、haml 的错还是其他库的错?

这是我的 Gemfile,以防万一我正在使用的东西可能出现问题:

source 'http://rubygems.org'
source 'http://gems.github.com'
source 'http://gemcutter.org'

gem 'rails', '3.2.1'
gem 'rake', '~> 0.9.2.2'
gem 'mysql2', '~> 0.3.11'
gem 'htmldoc'
gem 'haml', '~> 3.1.4'
gem 'sass', '~> 3.1.4'
gem 'hpricot'
gem 'curb'
gem 'mini_magick'
gem 'liquid', '~> 2.3.0'
gem 'httparty', '~> 0.8.1'
gem 'linkedin', '0.1.7', :require => 'linkedin'
gem 'twitter', '~> 2.0.2', :require => 'twitter'
gem 'mime-types', '>=1.16', :require => 'mime/types'
gem 'oauth'
gem 'roxml'
gem 'nokogiri'
gem 'sax-machine'
gem 'googlecharts', '1.6.7', :require => 'gchart'
gem 'pdf-reader', '~> 0.9.0'
gem 'paper_trail'
gem 'rubyzip', '0.9.4', :require => 'zip/zip'
gem 'activemerchant', '~> 1.20.2', :require => 'active_merchant'
gem 'compass', '~> 0.11.5'
gem 'compass-rgbapng', '0.1.1', :require => 'rgbapng'
gem 'fancy-buttons', '~> 1.1.1'
gem 'ruby-openid'
gem 'RedCloth', '~> 4.2.9'
gem 'koala', '~> 1.0.0'
gem 'scoped_search', '~> 2.3.6'
gem 'wicked_pdf', '0.7.0'
gem 'devise', '~> 2.0.0'
gem 'paperclip', '~> 2.5.0'
gem 'aws-sdk' # required for paperclip
gem 'whois', '~> 2.0.4'
gem 'validates_timeliness', '~> 3.0.8'
gem 'will_paginate', '~> 3.0.2'
gem 'hoptoad_notifier', '~> 2.4.11'
gem 'savon', '~> 0.9.2'
gem 'escape_utils'
gem 'ajaxful_rating', '3.0.0.beta3'
gem 'acts_as_list', '~> 0.1.3'
gem 'despamilator', '~> 2.0'
gem 'prawn', '~> 0.12.0', :submodules => true
gem 'net-dns', '~> 0.6.1'
gem 'authlogic', '~> 3.1.0'
gem 'myspaceid-sdk', '~> 0.1.11', :require => 'myspace'
gem 'in_place_editing', '~> 1.1.2'
gem 'deadlock_retry', '~> 1.1.2'
gem 'query_trace', '~> 0.1.1'
gem 'aasm', '~> 3.0.2'
gem 'vanity', '~> 1.7.1'
gem 'prototype-rails', '~> 3.2.1'

group :development, :test do
  gem 'rspec-rails', '~> 2.8.1'
  gem 'rspec'

  # one-liner to install these properly: bash < <(curl -L https://raw.github.com/gist/1333785)
  gem 'linecache19', '0.5.13'
  gem 'ruby-debug-base19', '0.11.26'

  gem 'capistrano'
end

group :test do
  gem 'factory_girl_rails'
  gem 'syntax'
  gem 'timecop', '~> 0.3.5'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'cucumber-rails', '~> 1.2.1'
  gem 'cucumber'
  gem 'launchy'
end

谢谢!

I'm upgrading my app from 3.0.9 to 3.2.1 (ruby 1.9.3-p0, rvm, bundler) and one thing that I haven't been able to track down yet is this problem. I have a controller spec (in spec/controllers) that renders views for each example. The template that it renders can have any undefined method (like calling "- blahblah" in the haml) and it causes the test to hang for over 30 seconds. Here is the error:

undefined local variable or method `blahblahblah' for #<#<Class:0x007fa84f76cc90>:0x007fa849c578c8>

I ran the debugger and the hang happened when trying to log the error itself. This happens in activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb line 22. So is this Rails' fault, haml's fault, or some other library?

Here is my Gemfile just in case something I am using may be the problem:

source 'http://rubygems.org'
source 'http://gems.github.com'
source 'http://gemcutter.org'

gem 'rails', '3.2.1'
gem 'rake', '~> 0.9.2.2'
gem 'mysql2', '~> 0.3.11'
gem 'htmldoc'
gem 'haml', '~> 3.1.4'
gem 'sass', '~> 3.1.4'
gem 'hpricot'
gem 'curb'
gem 'mini_magick'
gem 'liquid', '~> 2.3.0'
gem 'httparty', '~> 0.8.1'
gem 'linkedin', '0.1.7', :require => 'linkedin'
gem 'twitter', '~> 2.0.2', :require => 'twitter'
gem 'mime-types', '>=1.16', :require => 'mime/types'
gem 'oauth'
gem 'roxml'
gem 'nokogiri'
gem 'sax-machine'
gem 'googlecharts', '1.6.7', :require => 'gchart'
gem 'pdf-reader', '~> 0.9.0'
gem 'paper_trail'
gem 'rubyzip', '0.9.4', :require => 'zip/zip'
gem 'activemerchant', '~> 1.20.2', :require => 'active_merchant'
gem 'compass', '~> 0.11.5'
gem 'compass-rgbapng', '0.1.1', :require => 'rgbapng'
gem 'fancy-buttons', '~> 1.1.1'
gem 'ruby-openid'
gem 'RedCloth', '~> 4.2.9'
gem 'koala', '~> 1.0.0'
gem 'scoped_search', '~> 2.3.6'
gem 'wicked_pdf', '0.7.0'
gem 'devise', '~> 2.0.0'
gem 'paperclip', '~> 2.5.0'
gem 'aws-sdk' # required for paperclip
gem 'whois', '~> 2.0.4'
gem 'validates_timeliness', '~> 3.0.8'
gem 'will_paginate', '~> 3.0.2'
gem 'hoptoad_notifier', '~> 2.4.11'
gem 'savon', '~> 0.9.2'
gem 'escape_utils'
gem 'ajaxful_rating', '3.0.0.beta3'
gem 'acts_as_list', '~> 0.1.3'
gem 'despamilator', '~> 2.0'
gem 'prawn', '~> 0.12.0', :submodules => true
gem 'net-dns', '~> 0.6.1'
gem 'authlogic', '~> 3.1.0'
gem 'myspaceid-sdk', '~> 0.1.11', :require => 'myspace'
gem 'in_place_editing', '~> 1.1.2'
gem 'deadlock_retry', '~> 1.1.2'
gem 'query_trace', '~> 0.1.1'
gem 'aasm', '~> 3.0.2'
gem 'vanity', '~> 1.7.1'
gem 'prototype-rails', '~> 3.2.1'

group :development, :test do
  gem 'rspec-rails', '~> 2.8.1'
  gem 'rspec'

  # one-liner to install these properly: bash < <(curl -L https://raw.github.com/gist/1333785)
  gem 'linecache19', '0.5.13'
  gem 'ruby-debug-base19', '0.11.26'

  gem 'capistrano'
end

group :test do
  gem 'factory_girl_rails'
  gem 'syntax'
  gem 'timecop', '~> 0.3.5'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'cucumber-rails', '~> 1.2.1'
  gem 'cucumber'
  gem 'launchy'
end

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2025-01-10 09:16:48

我在 Github 上的 Rails 问题跟踪器中找到了这个问题的答案(到目前为止它仍然是一个未解决的错误)。问题结果是,当引发错误时,会检查 ActionDispatch::Routing::RouteSet 的实例,这显然会导致对象检查它所持有的每个项目。因此,RouteSet 越大,#inspect 花费的时间就越长。修复方法如下:

module ActionDispatch
  module Routing
    class RouteSet
      alias inspect to_s
    end
  end
end

有关该错误的更多信息,请参阅此处

I found the answer to this in the Rails issue tracker on Github (it's still an open bug as of this time). The problem turned out to be that when an error was raised, an instance of ActionDispatch::Routing::RouteSet was inspected, which apparently caused the object to inspect every item it was holding onto. So, the larger the RouteSet, the longer the #inspect took. Here is the fix:

module ActionDispatch
  module Routing
    class RouteSet
      alias inspect to_s
    end
  end
end

For more info on the bug, see here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文