An easy way to run tests on a gem?

2020-07-10 09:15发布

问题:

Is there a quick and easy way to test a gem which is already installed locally? Like:

gem test gem_name_to_test

rubygems docs says one can put gem: --run-tests in ~/.gemrc file to run unit tests when a gem is installed. I could not make it work though and that is not exactly what I need.

回答1:

There is "gem test" command, which may or may not be what you are looking for. It run tests agains the package and sends them to test.rubygems.org.

gem install rubygems-test
gem test gem_name_to_test


回答2:

You can navigate to the place the gem lives and run tests from there, so for example:

$ cd ~/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-0.4.0
$ rake spec

Note that additional dependencies may need to be installed via bundler or gem