【问题标题】:Rails 3.1, rspec, guard and spork is really slow on windowsRails 3.1、rspec、guard 和 spork 在 Windows 上真的很慢
【发布时间】:2011-11-06 19:50:26
【问题描述】:

我正在努力成为一名更好的测试人员。设置有这么多问题,我想知道它是否值得。

有人可以帮忙吗?

我在 windows 盒子上运行 Rails 3.1、rspec、guard capybara 和 spork。我使用guard-spork gem。这是我运行 bundle exec guard 时得到的结果

查看“在 421.87 秒内完成”这一行。那就是一个测试!

我看到我收到了一个错误,guard-spork 抱怨没有 fork 支持(Windows 问题),但稍后这一行“./magazine_slave.rb:22:in `run'”应该表明 magazine_slave 运行(Windows 运行spork 用杂志而不是叉子)。

有什么想法吗?

Guard is now watching at 'c:/Users/Andreas/My Documents/Aptana Studio 3 workspace/maktaba'
'awk' is not recognized as an internal or external command,
operable program or batch file.
'awk' is not recognized as an internal or external command,
operable program or batch file.
Starting Spork for Test::Unit & RSpec
ERROR: Guard::Spork failed to achieve its <start>, exception was:
NotImplementedError: fork() function is unimplemented on this machine
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-spork-0.3.1/lib/guard/spork/runner.rb:40:in `fork'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-spork-0.3.1/lib/guard/spork/runner.rb:40:in `spawn_child'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-spork-0.3.1/lib/guard/spork/runner.rb:23:in `launch_sporks'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-spork-0.3.1/lib/guard/spork.rb:17:in `start'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:322:in `send'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:322:in `run_supervised_task'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:320:in `catch'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:320:in `run_supervised_task'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:153:in `start'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:254:in `run_on_guards'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:253:in `each'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:253:in `run_on_guards'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:252:in `catch'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:252:in `run_on_guards'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:251:in `each'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:251:in `run_on_guards'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard.rb:152:in `start'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/lib/guard/cli.rb:68:in `start'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:in `send'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/gems/guard-0.8.8/bin/guard:6
c:/Ruby/Ruby187/lib/ruby/gems/1.8/bin/guard:19:in `load'
c:/Ruby/Ruby187/lib/ruby/gems/1.8/bin/guard:19

Guard::Spork has just been fired
Guard::RSpec is running, with RSpec 2!
Running all specs
F

Failures:

  1) UserCruds Creates a new user
 Failure/Error: click_button "Submit"
 ActionView::Template::Error:
   You have a nil object when you didn't expect it!
   You might have expected an instance of Array.
   The error occurred while evaluating nil.map
 # ./app/views/users/_form.html.erb:38:in `_app_views_users__form_html_erb___24339687_119563452'
 # ./app/views/users/_form.html.erb:3:in `_app_views_users__form_html_erb___24339687_119563452'
 # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___963176717_119608284'
 # ./app/controllers/users_controller.rb:52
 # ./app/controllers/users_controller.rb:47:in `create'
 # (eval):2:in `send'
 # (eval):2:in `click_button'
 # ./spec/requests/user_cruds_spec.rb:16
 # ./magazine_slave.rb:22:in `run'
 # magazine_slave_provider.rb:17

Finished in 421.87 seconds
1 example, 1 failure

【问题讨论】:

  • 新纪录! “在 1288.48 秒内完成”
  • 实际上需要这么长时间还是计时器错误? Rspec 改变了它的运行方式,据我所知,spork 还没有适应
  • 我没有计时,不过离实时不远了。

标签: ruby-on-rails testing


【解决方案1】:

因为 rspec 加载 rails 环境,所以速度很慢。你拥有的宝石越多,它变得越慢

这就是为什么 spork 是一个很棒的工具。它加载 rails 环境,guard 可以在不重新加载 rails 环境的情况下查找更改。但是guard-spork gem 中有一个错误。它不适用于 Windows,因为它依赖于 fork。即使是坚韧的叉子也不要在窗户上使用叉子,但叉子会。非 UNIX 系统不支持 Fork。

我研究了这个问题并最终采用了不同的方法。我制作了 lib 文件夹的逻辑,并且没有在规范中包含 spec_helper 文件。然后不会加载rails,只有特定的测试逻辑。这速度很快,迫使我编写更具可读性的代码。

查看 Cory Haines 的演讲中的 video,了解有关该主题的更多信息。

【讨论】:

    猜你喜欢
    • 2011-12-31
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2012-02-24
    • 2013-10-05
    • 2012-05-27
    • 2014-03-06
    • 1970-01-01
    相关资源
    最近更新 更多