2013-03-30 44 views
3

當我運行'rspec'或'bundle exec rspec'時,它不讓我在我的.gemspec文件中使用依賴關係。我是否必須重複自己並打破DRY原則,並在Gemfile和.gemspec中顯示我的寶石? (PS。我這樣做對我的模型文件作爲軌道引擎)我如何獲得rspec來讀取我的gemspec中的依賴關係?

的Gemfile:

gemspec 

.gemspec:

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

例子:

「捆綁EXEC rspec的」 顯示錯誤:

uninitialized constant Mongoid::Commentable 
uninitialized constant Comment::Mongoid_Commentable 
uninitialized constant Mongoid::Commentable 

回答

3

與使用Bundler/Gemfile不同,Gem依賴不是自動加載的。因此,你需要require你所依賴的寶石。

+0

你在哪裏通常自動加載這些,在spec_helper.rb? – Kamilski81

+0

通常你會在spec_helper中加載你的寶石。你的寶石應該將它的依賴加載到它的主文件中。 – fphilipe

相關問題