2

I'm creating a gem (let's call it mygem) that is essentially a Sinatra server intended to be mounted within Rack based apps.

Inside my gem's gemspec file, I have the following:

gem.add_dependency 'kss'

And Inside my gem's Gemfile, I have the following

source 'https://rubygems.org'

gemspec

gem "kss", :path => "/Users/me/code/kss"

Now when running the server from within mygem's folder, this works exactly as expected: instead of fetching out for the kss dependency, it will look on my local drive and load that version.

The problem comes in when I add mygem to a Rails test app Gemfile. In my Rails test app Gemfile, I have the following line:

gem "mygem", :path => "/Users/me/code/mygem"

I would expect, upon a bundle install, that Bundler would load mygem and its dependencies; but for the kss dependency, instead of loading the local dependency, Bundler actually does fetches out to rubygems to find and load it. I'm assuming because in this case, it's only reading from the gemspec line and not including my dependency override.

Is there anything I can do to fix this behavior? I'd very much like to be able to run and test this stuff locally, but Bundler doesn't seem to recognize dependency overrides from a higher level app.

I'm completely open to any suggestions or changes if I'm going about this the wrong way.

joeellis
  • 2,745
  • 7
  • 28
  • 45

1 Answers1

1

Dependencies listed in your gemspec will become dependencies of the implementing application, while dependencies defined in the Gemfile will not become dependencies of the implementing application. I think you should be able to simply adjust the Rails test app Gemfile to be:

gem "kss", :path => "/Users/me/code/kss"
gem "mygem", :path => "/Users/me/code/mygem"
Brad Werth
  • 17,411
  • 10
  • 63
  • 88
  • Hey, this worked great! And for development, this is a good solution. However, if I have a `kss` fork that I need to use when `mygem` is actually ready for production, I'm guessing I'll need to instruct users to add both these lines in their Gemfiles? With the way I have this setup, there is no other way to add this forked dependency through only the gemspec file, right? – joeellis Apr 06 '13 at 15:45
  • Actually, if you add the "real" gems (without the local path) to your gemspec, they should take precedence in the implementing applications, and work as you intend them to, with no extra work. If you want to use the local gems in the implementing app, just add the path to the gem file, as above, to "override" it. – Brad Werth Apr 06 '13 at 16:21
  • Right, but unless I'm mis-understanding you, I wouldn't be able to release `mygem` that is dependent on the `kss` fork without making users of `mygem` add both lines in the Gemfile of their implementing app (not that this is a huge issue, just a minor inconvenience until I can resolve the fork), right? – joeellis Apr 06 '13 at 19:14