2011-07-16 15 views
5

我是BDD的新手。每次我尝试使用黄瓜,我发现它很慢。我曾在两台不同的机器上尝试过使用Rails 3.0.9 & 3.1。其中一台机器是具有2 GB RAM的旧IBM ThinkPad笔记本电脑;另一个是4 GB RAM的PC [如果需要,我可以得到确切的规格]。两者都运行Fedora 14.运行测试时黄瓜很慢[在两个不同的Fedora机器上测试]

即使没有scnerios的新应用程序黄瓜需要几分钟。这是怎么一回事呢:

$ cucumber 
Using the default profile... 
--- about 2 minutes delay---- and then it says: 
0 scenarios 
0 steps 
0m0.000s 

相比之下,Rspec的是即时的:

rspec 
No examples found. 

Finished in 0.00005 seconds 
0 examples, 0 failures 

同时黄瓜说花了0m0.000s;它在现实中花了大约2分钟。而且,RSpec是即时的并且正确显示时间:0.00005秒。

这是正常的。我是否需要一些额外的宝石或设置来加快处理速度。

更新:这里是更多的数据:

先用黄瓜:

$time cucumber 
Using the default profile... 
0 scenarios 
0 steps 
0m0.000s 

real 0m53.489s 
user 0m37.051s 
sys 0m1.973s 

,然后用rspec的

$ time rspec spec/ 
No examples found. 


Finished in 0.00005 seconds 
0 examples, 0 failures 

real 0m1.925s 
user 0m1.032s 
sys 0m0.155s 

回答

1

你指责在缓慢错误的工具。什么是缓慢的Ruby和Rails的启动时间,而不是黄瓜。这是众所周知的。

+0

谢谢!那么解决方案是什么?为什么rspec更快! – RubyDev

+0

我的测试目前运行缓慢,但我的应用程序是在PHP中。 – Rimian

+0

我想说@Aslak是正确的。而且,我认为在黄瓜身上获得了一些经验,我认为他为此得到-4是相当不公平的。 – RubyDev

1

你不是唯一的一个,我停止使用,因为黄瓜它只是在我的电脑上花了太长时间。我的RSpec有点慢,只有当我看到大量的例子(70-100ish)时,与我看过的Rails演员和其他人民教程相比,但对我来说很好(10-12秒)。黄瓜花的时间是相同的地雷,我的规格是:

Windows 7 64bit 
Intel i3 3.19 Ghz 
4.00 Gb Ram 

它仍然拖累屁股,这很烦人,我要升级我的电脑只是为了得到这个跑得快!它可能是Windows 7的事情。

+0

我使用Ubuntu并且在测试运行之前延迟了大约20秒 –

+0

在railscasts测试中立即运行)) –

+3

在Windows上,Ruby一般速度很慢。另外,我还看到有关Windows上慢速运行的其他问题。 – RubyDev

8

好的。用叉勺,这里是数据再次:

Rspec的是快于早前更没有例子,我能感受到其中的差别:

$ time rspec --drb spec/ 

Finished in 0.00182 seconds 
0 examples, 0 failures 

real 0m1.495s 
user 0m0.952s 
sys 0m0.147s 

这里是黄瓜中的数据:

。 ..悬念....

$ time cucumber --drb 
Using the default profile... 
Disabling profiles... 
0 scenarios 
0 steps 
0m0.000s 

real 0m3.775s 
user 0m2.187s 
sys 0m0.367s 

哇,现在有显着的区别。如果你在main:Object(NoMethodError)中得到“未定义的方法`World”请使用spork版本0.9.0.rc9。

更新:这里是步骤,如果有人需要它们[Ruby 1.9.2 + Rails 3。1]:

的Gemfile:

group :development do 
    gem 'rspec-rails' 
end 

group :test do 
    gem 'database_cleaner' 
    gem 'rails3-generators' 
    gem 'factory_girl_rails' 
    gem 'cucumber-rails' 
    gem 'capybara' 
    gem 'spork', '0.9.0.rc9' 
end 

然后,运行捆绑安装:

bundle install 

[如果您正在使用的RSpec]

rails g rspec:install 
spork --bootstrap 

编辑投机/ spec_helper.rb和按照指示。基本上把所有的东西

之间
Spork.prefork do 
end 

黄瓜:

rails g cucumber:install --spork 

运行叉勺

bundle exec spork cuc 
运行测试:

rspec --drb spec/ 
cucumber --drb 

享受BDD!自动测试接下来!

更新:

您可以添加到--drb到.rspec没有--drb选项RSpec的运行。

更新:

刚刚意识到我不需要--drb黄瓜..用叉勺服务器上运行,以下就足够了:

cucumber features/ 
+1

哇 - 好多了!只是一个简单的说明....为了得到这个好处,你必须运行上面列出的黄瓜(例如只是简单的'cucumber'或'cucumber-profile wip')**不**'捆绑执行耙黄瓜'。 – cailinanne

+1

更新了Rails 3.1的解决方案..如果有人需要它。 – RubyDev