Reputation: 1029
For example, given Gemspec file:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "github_stats/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "github_stats"
s.version = GithubStats::VERSION
s.authors = ["Pura Dawid"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/puradawid/github_stats"
s.summary = "Project repository model wrapper and statistic fetcher."
s.description = ""
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 4.1.8"
s.add_runtime_dependency "github_api", "0.12.3"
s.add_development_dependency "sqlite3"
end
And Gemfile for Gods sake:
source 'https://rubygems.org'
# Declare your gem's dependencies in github_stats.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use a debugger
#gem 'byebug', group: [:development, :test]
#gem 'github_api', '0.12.3'
group :development do
gem 'byebug'
gem 'mocha'
gem 'guard'
gem 'guard-minitest'
end
group :test do
gem 'rake'
end
github_api
is commented out (it working obviously if i put it here).
As you can see, github_api is added as a dependency (it's a gem). Is it working? Of course not. Typing a Bundler.require
gives me:
[<Bundler::Dependency type=:runtime name="github_stats" requirements=">= 0">,
<Bundler::Dependency type=:development name="sqlite3" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="byebug" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="mocha" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="guard" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="guard-minitest" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="rake" requirements=">= 0">]
I saw this issue here, but i don't see a clean solution.
What is wrong with me? add_dependency
is not working as well add_development_dependency
but the last one make no sense here at all, even though i tried it too.
Bundler version 1.8.4
=> ruby-2.1.5 [ x86_64 ]
Thanks for help, folks!
Upvotes: 3
Views: 1584
Reputation: 1409
If you are interested - issue 1041. After reading it I come to the understanding, that is standard behaviour. The argument is that relying on bundler to require your gem dependencies is a bad practice. You should require your gems explicitly because your gem is supposed to work without bundler. Bundler is widely used but not a standard like ruby gems.
In case you still need some access to the gems needed by bundler you can use this hack:
Bundler.definition.specs # gives all gems' dependencies
Upvotes: 2