Rails 3.1、rspec、guard和fork在windows上真的很慢



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

有人能帮帮我吗?

我在一个windows盒子上运行Rails 3.1, rspec, guard capybara和spork。我用的是守卫叉宝石。这是我运行bundle exec guard

时得到的结果

看"421.87秒完成"这句话。这是一个测试!

我看到我得到了一个错误的guard- spark抱怨没有叉子支持(Windows问题),但后来这一行"。/magazine_slave。rb:22:在' run'"中,应该表示正在运行magazine_slave (Windows运行带有magazine而不是fork的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

因为rspec加载rails环境,所以它很慢。宝石越多,速度越慢

这就是为什么叉子是一个伟大的工具。它加载rails环境,并且guard可以在不重新加载rails环境的情况下查找更改。但警卫叉宝石里有个bug。它不能在windows上工作,因为它依赖于fork。即使是很硬的叉子也不要在窗户上用叉子。在非unix系统上不支持Fork。

我研究了这个问题,最后采用了不同的方法。我将逻辑分解到lib文件夹中,并且在specs中不包括spec_helper文件。然后不加载rails,只加载特定的测试逻辑。这是快速的,迫使我编写更可读的代码。

请查看Cory Haines的演讲视频,了解更多有关该主题的内容。

最新更新