3

我将 Rspec 与我的 Rails 3.2.11 应用程序一起使用。我已经安装并设置了 spork。我使用数据映射器作为 ORM。

然而,当 spork 运行时,运行一个测试需要一分钟多的时间。即使正在运行的测试是空的。肯定有什么不对劲。但我无法弄清楚到底是什么。

我的 test_spec 是这样的:

require "spec_helper"
require "cancan/matchers"

describe User do
end

我的规范帮助文件可以在这里找到:https ://gist.github.com/4593609

当我计时 rspec 时:

➜  books git:(dev) ✗ time rspec --drb spec/models/test_spec.rb
No examples found.


Finished in 1 minute 51.08 seconds
0 examples, 0 failures
rspec --drb spec/models/test_spec.rb  1.49s user 0.04s system 1% cpu 1:52.94 total

叉烧日志:

➜  books git:(dev) ✗ spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Spork is ready and listening on 8989!
Running tests with args ["spec/models/test_spec.rb"]...
Done.

Running tests with args ["spec/models/test_spec.rb"]...
Done.

这是针对空规范的。具有大量示例的规范需要更多时间。它运行需要这么长时间吗?

4

2 回答 2

4

运行测试时查看你的 test.log ,可能每个测试都完成了数据库设置,它占用了时间。

tail -f log/test.log 运行测试时

于 2013-01-22T10:33:16.010 回答
1

我找到了解决这个问题的方法。问题出在我的 spec_helper 文件中。

 config.before(:suite) {
   DataMapper.auto_upgrade!
 }

由于这些配置,Datamapper 每次运行测试时都会尝试自动升级。在评论此配置时,即使 spork 未运行,规范也开始正常工作。

于 2013-01-22T12:32:56.763 回答