Rails 3.0.9 下 Spork 和 Rspec 自动测试响应缓慢

发布于 2024-11-28 08:41:09 字数 2069 浏览 4 评论 0原文

一切都在起作用,但速度很慢。

我知道 Spork 正在工作,因为 rspec spec/ 在两秒内产生响应,并且我知道自动测试正在工作,因为当我更改控制器代码时它最终会产生适当的 Growl 通知。问题是 Autotest 响应时间太长:大约 16 秒。请帮我弄清楚出了什么问题。

我是 Rails 新手,正在学习 Michael Hartl 的 Rails 3 教程。

Platform:   Mac OS X 10.5.8
            Xcode 3.1.4
Ruby:       v. 1.9.2 p180  (with RVM)
Rails:      v. 3.0.9

就其价值而言,我使用 Bundler 安装了 Autotest 和 Spork,并使用 bundle exec sporkbundle exec autotest 调用它们(每个都在其自己的终端窗口选项卡下) 。 spork(没有“bundle exec”)也运行良好,但是autotest(没有“bundle exec”)会产生“command not find”错误消息。

我的项目的 Gemfile(取自 Hartl 的教程书和视频):

source 'http://rubygems.org'

gem 'rails', '3.0.9'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '2.4.0'
  gem 'faker', '0.3.1'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'spork', '0.9.0.rc8'
  gem 'autotest', '4.4.6'
  gem 'autotest-rails-pure', '4.1.2'
  gem 'autotest-fsevent', '0.2.4'
  gem 'autotest-growl', '0.2.9'
  gem 'factory_girl_rails', '1.0'
end

我的项​​目的 .autotest 文件(也取自 Hartl):

require 'autotest/growl'
require 'autotest/fsevent'
Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
    autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
  end  
end

会发生什么:

当我将更改保存到我的一个controller.rb 文件(或controller_spec.rb 文件),大约 8 秒后,自动测试终端选项卡上出现任何活动 - 此时,它只是一行连字符,前后是一些空行。大约 7 秒后,自动测试选项卡显示以下消息:

/Users/jlee/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -rrubygems -S /Users/jlee/rails_projects/sample_app_jbl/自动测试/ruby/1.9.1/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/jlee/rails_projects/sample_app_jbl/spec/controllers/pages_controller_spec.rb'

随后几乎立即出现 spork 终端选项卡上的活动,以及所有终端窗口和咆哮通知中测试的预期结果。所以一切都在起作用,只是慢慢地!我渴望获得有关如何缩短自动测试响应的前十五秒的建议。

2011年8月7日

It's all working, but slowly.

I know that Spork is working, because rspec spec/ produces a response in under two seconds, and I know Autotest is working, since it eventually produces an appropriate Growl notification when I make a change to the controller code. The problem is that Autotest is taking too long to respond: about 16 seconds. Please help me figure out what's going wrong.

I'm new to Rails, and following Michael Hartl's Rails 3 Tutorial.

Platform:   Mac OS X 10.5.8
            Xcode 3.1.4
Ruby:       v. 1.9.2 p180  (with RVM)
Rails:      v. 3.0.9

For what it's worth, I installed Autotest and Spork using Bundler, and call them (each under its own terminal window tab) using bundle exec spork and bundle exec autotest. spork (without the "bundle exec") also runs fine, but autotest (without the "bundle exec") produces a "command not found" error message.

My project's Gemfile (drawn from Hartl's tutorial book and video):

source 'http://rubygems.org'

gem 'rails', '3.0.9'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '2.4.0'
  gem 'faker', '0.3.1'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'spork', '0.9.0.rc8'
  gem 'autotest', '4.4.6'
  gem 'autotest-rails-pure', '4.1.2'
  gem 'autotest-fsevent', '0.2.4'
  gem 'autotest-growl', '0.2.9'
  gem 'factory_girl_rails', '1.0'
end

My project's .autotest file (also drawn from Hartl):

require 'autotest/growl'
require 'autotest/fsevent'
Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
    autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
  end  
end

What happens:

When I save a change to one of my controller.rb files (or controller_spec.rb files), about 8 seconds elapse before there is any activity on the autotest terminal tab - which, at this point, is simply a row of hyphens preceded and followed by some empty lines. About 7 seconds later, the autotest tab displays the following message:

/Users/jlee/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -rrubygems -S /Users/jlee/rails_projects/sample_app_jbl/autotest/ruby/1.9.1/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/jlee/rails_projects/sample_app_jbl/spec/controllers/pages_controller_spec.rb'

Which is followed almost immediately by activity on spork's terminal tab, and the expected results of the test in all terminal windows and in a growl notification. So it's all working, just S-L-O-W-L-Y! I'm eager for suggestions about how to cut the first fifteen seconds out of autotest's response.

8/7/2011

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

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

发布评论

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

评论(1

夜访吸血鬼 2024-12-05 08:41:09

尝试将 --drb 添加到项目根目录下的 .rspec 文件中: http://maxjustus.tumblr.com/post/1322305832/rspec-2-rails-3-autotest-and-spork

Try adding --drb to the .rspec file at the root of your project: http://maxjustus.tumblr.com/post/1322305832/rspec-2-rails-3-autotest-and-spork

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