Question

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.

Was it helpful?

Solution

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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top