Wednesday, October 27, 2010

Ruby On Rails: rspec failing with [no such file to load -- spec_helper]

I have started reading www.railstutorial.org. It is wonderful tutorial for learning Ruby on Rails (ror). I am at chapter 3 currently and tried to setup the unit testing.
After creating project and generating controllers, I installed growl for windows and then autotest, autotest-growl gems. But when I issued the following command:

rspec .\spec\controllers\pages_controller_spec.rb
I got following error:

:29:in `require': no such file to load -- spec_helper (LoadError)
 from :29:in `require'
 from F:/Code/Learning/ruby/todo/spec/controllers/pages_controller_spec.rb:1:in `'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Going through much pain of reinstalling quite a few gems and banging my head, I went back to read the tutorial page again from beginning and make list of what I have already done as given in page. I found out that I had missed to execute following command:

rails generate rspec:install
It did the folowing:
create .rspec
  exist  
 create  spec/spec_helper.rb
 create  autotest
 create  autotest/discover.rb

Now I had got spec_helper.rb in my spec folder and was able to execute the tests (happily ever after ^_* ).

Also remember to install win32console-color gem to get colorfull info with autotest.
Happy Coding!