Select Page

uninitialized constant Test::Unit::TestResult::TestResultFailureSupport Error

Today trying to run my RSpec tests and I get an odd error:

uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError)
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:105:in const_missing'
/usr/local/lib/ruby/gems/1.8/gems/test-unit-2.0.3/lib/test/unit/testresult.rb:28
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
gem_original_require’
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:158:in
require’
….

After doing some research online I found out that the issue is caused by Shoulda and Mocha being included in my app. It seems that if you put a gem dependence for Shoulda before Mocha,  you’ll get this error, so the fix is to place the gem dependence for Mocha before Shoulda.

config.gem “rspec”, :lib => false, :version => “>=1.2.6”
config.gem “rspec-rails”, :lib => ‘spec/rails’, :version => “>=1.2.6”
config.gem “mocha”
config.gem “thoughtbot-shoulda”, :lib => “shoulda”, :source => “http://gems.github.com”

Hope that helps

UPDATE:

I hit the same error having shoulda in my environment.rb file, moving it to the test.rb (in environment folder) fixed the issue as well.

Error with fsevent and autospec (on Mac)

Today I’ve upgraded my gems and noticed that when running my autospec I get an odd error:

[01:09:25 /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.10/lib/ole/storage/base.rb:146:load]

WARN   root name was “R”

And my autospec would keep printing out:
sh: line 1:  6303 Trace/BPT trap          /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.1.2/fsevent/darwin/fsevent_sleep ‘/Users/andrew/rails_apps/example_com’ 2>&1
sh: line 1:  6307 Trace/BPT trap          /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.1.2/fsevent/darwin/fsevent_sleep ‘/Users/andrew/rails_apps/example_com’ 2>&1
Unfortunately I don’t have the time to look into the fsevent code to see if I can make a work around, however I found that you can remove the gem (‘sudo gem uninstall autotest-fsevent‘) and install the older version (‘sudo gem install autotest-fsevent --version 0.1.1‘)
Hopefully this helps someone out!
UPDATE: I forgot to mention I was using a Mac OS X 10.5.8, and based on the History.txt they made changes effecting Macs.
UPDATE 2 (Oct 22, 09): It seems that the same issue exists in fsevent 0.1.3 as well
UPDATE 3 (Mar 05, 2010): Issue still present in 0.2.1 however I found out that the error is only for OS X 10.5 and will not happen on OS X 10.6.
The full error message is:

/usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.2.1/fsevent/darwin/fsevent_sleep ; exit;
~%  /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.2.1/fsevent/darwin/fsevent_sleep ; exit;
dyld: unknown required load command 0x80000022
zsh: trace trap

The only work around (outside of downgrading to version 0.1.1) is to copy fsevent_sleep from version 0.1.1 to version 0.2.1. However I’m not sure how stable that solution is.

ERROR: While executing gem … (Zlib::BufError) in windows

So today I’m trying to update my gems and I get this error on random gems like rspec-rails but rspec updated fine.

I googled the issue and found great articles on the error, unfortunately none of them really worked. This brought me to posting what I did to fix it the error.

First, based on dontrepeatyourself, I updated to the latested gem system (version 1.3.3).
gem update --system
Based on what I’ve read on the site, it fixed the issue for a lot of people (keep in mind this is an article from 2007) but it didn’t fix my issue. I continued looking for another solution, and I found a bunch of Window’s specific fixes that involved altering ruby code which I wasn’t going to attempt. Some article comments said to re-install ruby but who has time for that? Other posts (in the comments) said to download windows specific GZip ports but that also had no effect. I even installed a zliby gem hoping it would replace the Zlib but that still didn’t work. So I did what every windows user should do when the problem isn’t getting fixed, REBOOT!. After the reboot, gems updated without a problem (well except of the usual SQLite3 update error on windows

Long story short

try calling
gem update --system
And then Reboot your system and see if that fixes it

Please leave me a comment to let me know if this helped you

Rails 2.3 Templates on Windows

In Rails 2.3, templates are simple ruby files containing DSL for adding plugins, gems, initializers, etc. to your freshly created Rails project. To apply the template, you need to provide the rails generator with location of the template you wish to apply, using -m option.

Reading up on the commands in the template system and watching the railscasts.com episode, I got fired up on the possibilities of such a simple yet amazing system. So I dove in and started creating my base template. I was so excited that I write the whole template out in one go and than ran it. The result: FAIL!

After including some gems, I ran a rake "gems:install" and ended up with an Exec format error. I googled the problem and found that mostly Windows users were getting this error and the recommend solution was to use a rake.bat (or rake.cmd) instead of the rake command from ruby. So I wrote my own function:

#HELPERS
def win_env?
RUBY_PLATFORM=~ /win32/
end

def rake(command, options = {})
env = options[:env] || 'development'
log 'rake', "#{command} in #{env} "
sudo = win_env? ? '' : (options[:sudo] ? 'sudo' : '')
rake_cmd = win_env? ? "rake.bat" : 'rake'
in_root { run("#{sudo} #{rake_cmd} #{command} RAILS_ENV=#{env}", false) }
end

Another thing that I was able to fix is the “Sudo” option, works great on UNIX systems but not so great in Windows. I haven’t been able to test it but I’m pretty sure this will work on a UNIX system without any issues.

All worked out great till I ran run "cucumber features -n" and got the exact same error! Lucky there was a .bat version of cucmber command so I was able to easily fix it by calling run "cucumber#{win_env? ? '.bat': ''} features -n"

One more small issue I found in Windows when making a template was in the git command. When doing a commit you need to use double quotes inside the commit message otherwise you get an error: pathspec 'commit'' did not match any file(s) known to git.

If you’re interested in downloading my template, you can download it from here

If you really want to see the power of template system I recommend you read the template_runner.rb in the rails folder. Enjoy and have fun with it!

Installing/Updating SQLite3 on Windows

Installing SQLite3 DLL

To install SQLite3 in windows you require not only the gem but a DLL files in your system PATH (or in your windows/system32 folder).

To obtain the DLL, go to: http://www.sqlite.org/download.html

I always believe that DLLs belong in the windows/system32 folder but as long as you put yours somewhere where your PATH environment variable points to, you should be fine.

Installing/Updating the SQLite3 Gem

Normally to install the gem you’d call gem install sqlite3-ruby and it would do everything automatically but if you try it (as of today) it will give you the following error:

C:>gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

c:/ruby/bin/ruby.exe extconf.rb install sqlite3-ruby
checking for fdatasync() in rt.lib... no
checking for sqlite3.h... no

nmake
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Gem files will remain installed in
c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to
c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out

As not helpful as that error message is, it turns out that the new version of sqlite3-ruby doesn’t have a win32 version (which is needed for it to install/function correctly). So all you have to do is specify an older version of sqlite3.

To install a older version of a gem, run:

gem install --version 1.2.3 sqlite3-ruby

Now you’re all set to go!

Once sqlite3 is installed and you try to update the rest of your gems calling gem update, it will fail because (as of September 8th) sqlite3-ruby doesn’t have a win32 version of the 1.2.4 gem. To get around this, remove the sqlite3-ruby gem (gem uninstall sqlite3-ruby), then call gem update and then reinstall the gem by calling gem install –version 1.2.3 sqlite3-ruby.

SOURCE:

The most helpful site online that helped me figure this out was: http://www.ruby-forum.com/topic/164116

UPDATE:

I just tired updating the gems myself and had to uninstall sqlite3-ruby (it seems as of October 21st, 2008, they still haven’t fixed the issue!) and I copied the command of my own blog to find it doesn’t work. Not sure if it’s just firefox or wordpress but the problem is in the way the page is rendered, the “- – version” has a double dash (without the space) but the browser changes the html and makes it one dash. So I attempted to put it in a different format. So for those who had issues before, you can now copy the code above and just make sure that the version has a double dash in front of it.