开发者

Gem Development Workflow

I'm working on a fork of someone's gem that is a command line utility. Here's a general overview of the directory structure:

bin/
bin/foo

lib/
lib/foo.rb
lib/foo/bar.rb (etc)

To test it, I normally do something like this:

cd bin/
./foo <args>

But I want to be able to use it from any directory (like it would be once instal开发者_Python百科led). My question is if it's possible to achieve this without installing the gem on my system each time.

My first attempt at this was to create a symbolic link to the foo script that was on my PATH, but this messes with the require 'foo' line in the script since File.dirname(__FILE__) now refers to wherever the symbolic link was created.

Is there a common way of doing this?

(Oh, and here's the relevant lines from the foo script)

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'foo'

(EDIT)

I'm aware of the normal ways of testing a library (ie rake test, etc)--I'm specifically interested in using the script from any directory without reinstalling the gem with every change (if possible).


In almost every gem I've looked into, there is a rakefile of some sort. In which case you go to the root of the gem, and go:

rake test

For a list of tasks, use:

rake -T

(This assumes you have rake installed in the first place, obviously: gem install rake if not.)

Also, many a gem also features a gemfile. In this case you can use bundler to install applicable dependencies (in particular, test suites and development-related gems).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜