Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber is very slow when running tests [Tested on two different Fedora machines]

I am new to BDD. Every time I try using cucumber, I find it pretty slow. I have tried with Rails 3.0.9 & 3.1 on two different machines. One of machines is an old IBM thinkpad laptop with 2 GB ram; and the other one is a PC with 4 GB RAM [I can get exact specifications if required]. Both run Fedora 14.

Even with a new application with no scnerios Cucumber take minutes. Here is how it goes:

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

In contrast, Rspec is instant:

rspec
No examples found.

Finished in 0.00005 seconds
0 examples, 0 failures

While cucumber says it took 0m0.000s ; it has taken about 2 minutes in reality. And, RSpec was instant and shows the time correctly as well: 0.00005 seconds.

Is this normal. Do I need some additional Gems Or settings to make the process faster.

Update: Here is more data:

First with cucumber:

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

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

and then with 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
like image 777
Chandresh Pant Avatar asked Jul 16 '11 18:07

Chandresh Pant


3 Answers

You're blaming the slowness on the wrong tool. What's slow is Ruby and Rails' startup time, not Cucumber. This is well known.

like image 23
Aslak Hellesøy Avatar answered Nov 16 '22 00:11

Aslak Hellesøy


Ok. Used Spork, and here is the data again:

Rspec is faster then earlier even with no examples, I can feel the difference:

$ time rspec --drb spec/

Finished in 0.00182 seconds
0 examples, 0 failures

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

And Here is the data for Cucumber:

... suspense....

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

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

Wow, there is marked difference now. If you get "undefined method `World' for main:Object (NoMethodError)" Please use spork version 0.9.0.rc9.

Update: Here are the steps, if someone else needs them [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

Then, run bundle install:

bundle install

[If you are using rspec]

rails g rspec:install
spork --bootstrap

edit spec/spec_helper.rb and follow instructions. Basically put everything between

Spork.prefork do
end

for cucumber:

rails g cucumber:install --spork

Run spork

bundle exec spork cuc

Run tests:

rspec --drb spec/
cucumber --drb

Enjoy BDD!! Autotest next!

Update:

You can add --drb to .rspec to run rspec without the --drb option.

Update:

Just realized I don't need --drb with cucumber.. with a spork server running, following would be sufficient:

cucumber features/
like image 104
Chandresh Pant Avatar answered Nov 16 '22 00:11

Chandresh Pant


You're not the only one, I stopped using cucumber because it just took too long on my computer. My RSpec is a little bit slow only if I get a lot of examples (70-100ish) compared to the Rails-casts and other peoples tutorials I've watched but to me its fine(10-12 sec). Cucumber took the same amount of time on mine, my specs are:

Windows 7 64bit
Intel i3 3.19 Ghz
4.00 Gb Ram

And it still drags ass, it's annoying that I have to upgrade my computer just to get this to run fast! It a could be Windows 7 thing.

like image 1
LearningRoR Avatar answered Nov 16 '22 02:11

LearningRoR