3

When I run 'rspec' or 'bundle exec rspec' it doesn't let me use the dependencies in my .gemspec file. Do I have to repeat myself and break the DRY principle and display my gems in Gemfile and .gemspec?? (ps. I am doing this for my models files as a rails engine)

Gemfile:

gemspec

.gemspec:

  s.add_dependency "rails", "~> 3.2.13"
  s.add_dependency "mongoid"
  s.add_dependency "mongoid_commentable"

Example:

"bundle exec rspec" Displays errors:

uninitialized constant Mongoid::Commentable
uninitialized constant Comment::Mongoid_Commentable
uninitialized constant Mongoid::Commentable
Kamilski81
  • 14,409
  • 33
  • 108
  • 161

1 Answers1

4

Gem dependencies are not autoloaded as opposed to using Bundler/Gemfile. Thus, you'll have to require the gems that you depend upon.

fphilipe
  • 9,739
  • 1
  • 40
  • 52
  • where do you typically autoload these, in spec_helper.rb? – Kamilski81 Mar 30 '13 at 21:04
  • Usually you load your gem in the spec_helper. Your gem should be loading it's dependencies in its main file. – fphilipe Mar 30 '13 at 22:07
  • You should also think about adding it to the ruby file in gem which the main app loads e.g. if your gem is my_gem you should add the dependency in lib/my_gem.rb file – sethi May 30 '23 at 01:05