2013-01-22 149 views
2

我在使用Rspec和我的Rails 3.2.11应用程序。我已经安装并设置spork。 我使用数据映射器作为ORM。Rspec加载太长时间

然而,当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. 

这是一个空的规范。有很多例子的规格需要更多时间。 什么可以采取这么长时间才能运行?

+0

你连接到远程数据库吗?数据库表是否有太多列?我认为你的情况都是如此:P – piyush

回答

1

时,我发现这个问题的解决方案。问题出在我的spec_helper文件的 。

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

由于这些CONFIGS的,DataMapper的试图每个我跑测试时间自动升级 。在评论此配置时,即使spork未运行,spec也开始 正常工作。

1

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

tailf log/test.log 运行测试

+0

我尾巴test.log文件,我很震惊。 “SHOW COLUMNS FROM'model'LIKE'属性'”查询针对每个模型及其属性运行。 我应该怎么做才能防止这种情况? – arkiver

+0

你正在运行服务器的模式? –

+0

@yashir请你详细说明一下吗? – arkiver