Can't config.gem from test.rb - has to be in environment.rb

25 views
Skip to first unread message

Cynthia Kiser

unread,
Jun 22, 2009, 4:50:50 PM6/22/09
to Shoulda Mailing List
I am having some really odd problems as I try to upgrade my Shoulda
versions (from 2.0.6 to 2.10.1) in preparation for upgrading my Rails
app. I think the main issue is that I would like to move to just using
the Shoulda gem (I have been using it as a Rails plugin (in
vendor/plugins) for a long while).

So, why do the instructions at
http://rdoc.info/projects/thoughtbot/shoulda
say to unpack the gem into vendor/gems? Is that neccessary? It doesn't
appear to be - as long as I put the config.gem line in
$RAILS_ROOT/config/environment.rb. Then, with a little bit of tweaking
for syntax changes, my tests run file.

But if I try to move the config.gem line into
$RAILS_ROOT/config/environments/test.rb, the 'rake gems' tasks seem to
think it is fine, but 'rake test' doesn't load the correct version and
I get very old versions of Shoulda complaining about macros not found.
What am I missing about gem/plugin loading? And is the answer really
to RTFM and do "rake gems:unpack"?

Current Rails: 2.1.2

Installed Gems:
seanhussey-woulda (0.2.2, 0.2.0, 0.1.6)
Shoulda (1.2.0, 1.1.1)
thoughtbot-shoulda (2.10.1, 2.9.1, 2.0.6)


enviroment.rb

config.gem 'mime-types', :lib => 'mime/types', :version => '1.15'
config.gem 'editable-image', :version => '0.25'
config.gem 'rmagick', :lib => 'RMagick', :version => '>= 1.15.13'

environments/test.rb

# Gems we only need for testing
config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :version => '2.10.1', :source => 'http://gems.github.com'
config.gem 'mocha'
config.gem 'feedvalidator', :lib => 'feed_validator'

$ rake gems
(in /rails/grapevine)
[I] mime-types = 1.15
[I] editable-image = 0.25
[I] rmagick >= 1.15.13

$ rake gems RAILS_ENV=test
(in /rails/grapevine)
[I] mime-types = 1.15
[I] editable-image = 0.25
[I] rmagick >= 1.15.13
[I] thoughtbot-shoulda = 2.10.1
[I] mocha
[I] feedvalidator


$ rake test:units
/software/stow/ruby-enterprise-1.8.6-20080709/bin/ruby -I"lib:test"
"/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"
"test/unit/site_image_test.rb" "test/unit/page_test.rb" "test/unit/document_test.rb" "test/unit/event_test.rb"
"test/unit/document_category_test.rb" "test/unit/ldap_server_test.rb" "test/unit/role_test.rb" "test/unit/user_test.rb"
"test/unit/layout_test.rb" "test/unit/homepage_image_test.rb" "test/unit/site_preference_test.rb"

/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/Shoulda-1.2.0/lib/shoulda.rb:273:in
`send': undefined method `should_belong_to' for PageTest:Class (NoMethodError)
from
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/Shoulda-1.2.0/lib/shoulda.rb:273:in
`
method_missing' from ./test/unit/page_test.rb:6:in `__bind_1245701310_688247'

Ken Collins

unread,
Jun 22, 2009, 6:01:44 PM6/22/09
to sho...@googlegroups.com

I use "shoulda/rails" as the lib in my test.rb. Does that help?

- Ken

Cynthia Kiser

unread,
Jun 23, 2009, 1:13:59 AM6/23/09
to sho...@googlegroups.com
Quoting Ken Collins <k...@metaskills.net>:
> I use "shoulda/rails" as the lib in my test.rb. Does that help?

Sort of. With the following line in my environments/test.rb

config.gem 'thoughtbot-shoulda', :lib => 'shoulda/rails', \


:version => '2.10.1', :source => 'http://gems.github.com'

I can show that I am loading the right version of the shoulda
gem. I know that from the stack trace for the new error message (same
for all sets of tests (unit, functional, and integration)

/software/stow/ruby-enterprise-1.8.6-20080709/bin/ruby -I"lib:test"
"/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"

"test/unit/site_image_test.rb" "test/unit/page_test.rb"...

/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/\
dependencies.rb:440:in `load_missing_constant': uninitialized constant Shoulda::Assertions (NameError)
from
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing'
from
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb:22
from
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require' ....

Bharat

unread,
Jun 23, 2009, 11:05:29 AM6/23/09
to shoulda
Hello Cynthia,
I think you may have the "old" version of Shoulda being pointed to.
Have you run the rake Install command after adding the line:
config.gem 'thoughtbot-shoulda', :lib => 'shoulda/rails', \
:version => '2.10.1', :source => 'http://gems.github.com'
line to your test.rb file?
You an easily check that by going to your gems directory or doing a
gem list command. If you have MRI and Enterprise Ruby both then make
sure that the gem ends up being where it is supposed to be.
Bharat

Cynthia Kiser

unread,
Jun 23, 2009, 12:17:26 PM6/23/09
to sho...@googlegroups.com
Quoting Bharat <bcru...@yahoo.com>:
> I think you may have the "old" version of Shoulda being pointed to.

I know I have an old version being loaded (the error message lists
version), what I don't know is why.

> You an easily check that by going to your gems directory or doing a
> gem list command.

My original post shows which versions of shoulda I have installed as
gems - and it includes the 2.10.1 thoughtbot-should gem referenced in
my config.gem statement. It just isn't being used if I move my gem
requirement from environment.rb to test.rb

--
Cynthia Kiser
c...@caltech.edu

Michael Breen

unread,
Jun 23, 2009, 12:33:38 PM6/23/09
to sho...@googlegroups.com
Hi Cynthia.

On Jun 23, 2009, at 12:17 PM, Cynthia Kiser wrote:

>
> Quoting Bharat <bcru...@yahoo.com>:
>> I think you may have the "old" version of Shoulda being pointed to.
>
> I know I have an old version being loaded (the error message lists
> version), what I don't know is why.

You probably already did this but I figured it wouldn't hurt to ask
anyway ;)

Did you delete the old shoulda version from vendor/plugins?

Best.
Mike

Cynthia Kiser

unread,
Jun 23, 2009, 12:42:15 PM6/23/09
to sho...@googlegroups.com
Quoting Michael Breen <har...@gmail.com>:
> You probably already did this but I figured it wouldn't hurt to ask
> anyway ;) Did you delete the old shoulda version from vendor/plugins?

It never hurts to double check. Yes, I have no shoulda anything in my
vendor/plugins directory. And what I am trying to do is to avoid
having shoulda in vendor/gems as the install instructions imply one
should do. If I am going to have to install shoulda in my production
environment, at least I only want the single copy in my shared gems
location.

Bharat

unread,
Jun 23, 2009, 1:00:09 PM6/23/09
to shoulda
Cynthia,
Have you sym-linked your Enterprise Ruby executables? Or do you just
have Enterpriseruby/bin in your path? I have had no ends of trouble
because of that in my production environment. I am using MRI in
development so it is a mute issue.
Bharat
Reply all
Reply to author
Forward
0 new messages