Monday, May 17, 2010

An issue with Rspec on Windows



Rspec is a very popular test framework used to test Rails application. I have tried to install and use it for my Rails projects on Windows. It raised a bug when I ran tests:
c:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in load_missing_constant': uninitialized constant RbReadline::Encoding (NameError)
from c:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4404 
I traced back and found these causing lines:
   if defined? ''.getbyte
      @encoding = "X"      # ruby 1.9.x or greater
      @encoding_name = Encoding.default_external.to_s
   end
It seems the Rspec uses Ruby Readline library for its command-line interface. It defined getbyte that uses Encoding module which hasn't been defined in this Ruby package on Windows. I then commented out the line using Encoding module and the bug get fixed...
   if defined? ''.getbyte
      @encoding = "X"      # ruby 1.9.x or greater
      # @encoding_name = Encoding.default_external.to_s
   end
It's not common to pass over the issue by this way but hopefully it still works fine in my case.

1 comment:

Anonymous said...

How did you install Rspec on Windows? I installed the rspec and rspec-rails gems, but I can't run rspec from the command-line. Most of the other gems I install (like Rails or Autotest) all put a .bat file in my \Ruby\bin directory, Rspec didn't. Any ideas?