gems with add_dependency are not required when using gemspec in Gemfile

1,698 views
Skip to first unread message

Balint Erdi

unread,
Apr 14, 2013, 9:16:01 AM4/14/13
to ruby-b...@googlegroups.com
Hey,

I'm building a Rails engine that uses activeadmin that, in turn, installs an initializer. When the initializer runs, it supposes that the top-level module, ActiveAdmin is already loaded.

Here are the relevant snippets:

config/initializers/active_admin.rb:

ActiveAdmin.setup do |config|
   (...)
end

Gemfile:


gemspec
(...)

myapp.gemspec:

s.add_dependency "rails", "~> 3.2.13"
s.add_dependency "activeadmin", "~> 0.5.1"
(...)

s.add_development_dependency "sqlite3"
s.add_development_dependency "debugger", "~> 1.5.0"
s.add_development_dependency "rspec-rails", "~> 2.13.0"
s.add_development_dependency "capybara", "~> 2.1.0"

It then breaks, because it is not. Looking at how Bundler loads dependencies, I realized that when the Gemfile contains a `gemspec` line, it only loads the gems that are defined with `add_development_dependency`.

I wonder what the reasoning behind this is. Is there a best practice or some consideration I'm not aware of?

Thank you,
Balint

André Arko

unread,
Apr 20, 2013, 1:31:45 AM4/20/13
to ruby-b...@googlegroups.com
Adding dependency lines to your Gemspec only tells Rubygems to add those gems to the load path, it doesn't require them for you. Gems are required (by Rubygems itself) to add require statements for any ruby file that they depend on. Add the require statements that you need, and things will then work for you.

Development dependencies are loaded by Bundler due to a quirk in how we hacked support for development dependencies from gems into bundler in the first place.

I currently suggest that gems list only rake and bundler in the gemspec development dependencies, and then list the rest of the development dependencies in the :development group in their Gemfile.


--
You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-bundler...@googlegroups.com.
To post to this group, send email to ruby-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-bundler?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages