5

My Rails site uses a certain gem which is really not very good. Every time I need to do something new I end up having to spend as much time adding features to the gem as I do adding code to the actual Rails project. But I don't mind, and I have my Gemfile set up to point to my GitHub fork of the gem (I tried submitting PRs, but the maintainer seems to have stepped down).

The problem is that I really haven't found a sane way of testing new things I add to the gem. It'd be especially nice to test it within rails c, but the only ways I can think of doing that are a) Changing ~/.rvm/gems/.../foo.rb, which doesn't seem right or b) Bumping the version, pushing to Github, and running bundle up, which in addition to being time-consuming is obviously a disaster since I don't know for sure whether the commits I make are right or not.

I'd even be perfectly happy with a standard irb. But various permutations of require lib/foo from within the gem's directory don't work.

So what's the best practice here?

4

1 回答 1

10

If you are using a gem and working on it at the same time, the best way is to use Bundler and provide a local path:

gem 'my_bad_gem', path: '../my_bad_gem/'

This will look for the gem under the given (relative in this case) path. Another option is to use local git repositories (see http://bundler.io/v1.3/git.html).

于 2013-08-23T17:37:30.187 回答