ruby-on-rails - Rails 3.1、rspec、guard 和 spork 在 Windows 上真的很慢

标签 ruby-on-rails testing

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

有人可以帮忙吗?

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

查看“Finished in 421.87 seconds”这一行。这是一个测试!

我发现 guard-spork 出现错误,提示没有 fork 支持(Windows 问题),但稍后这一行“./magazine_slave.rb:22:in `run'”应该表明 magazine_slave 运行(Windows 运行用杂志代替 fork )。

有什么想法吗?

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 环境,它很慢。你拥有的 gem 越多,速度越慢

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

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

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

关于ruby-on-rails - Rails 3.1、rspec、guard 和 spork 在 Windows 上真的很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8029912/

相关文章:

perl TAP 测试:如何从 TAP::Formatter::HTML 输出中获取失败测试的计数?

django - 测试 REST 访问是否必要/好?

ruby-on-rails - 在rails中继承active_record

css - Rails application.css.scss 不知道其他正在使用的 scss 文件?

ruby-on-rails - 如何从 Rails 中的枚举中获取整数值?

testing - 数据流覆盖

android - 测试 Android Activity

ruby-on-rails - Rails中两个类之间的多个belongs_to关系

ruby-on-rails - Rails 3 Devise 停止使用更多加密 "stretches"

testing - 基于状态的测试(状态图)和转换序列