Chris Cummings
Chris Cummings

Reputation: 2067

How can I run a gem's tests when using bundler

I have a private gem (built with jeweler) hosted on Github. I run unit tests before I commit but I'd like to test everything works when I use bundler from the end-user side.

So far I've just been creating a test environment with two files:

Gemfile:

gem 'my_gem', :git => '[email protected]:my_repo/my_gem.git'

main.rb:

require "rubygems"
require "bundler/setup"
require "my_gem"

# Some code calling arbitrary methods from my gem

It seems like there's probably a way for me to run the unit tests built in to the gem.

Upvotes: 0

Views: 309

Answers (1)

Aaron Massey
Aaron Massey

Reputation: 3986

Bundler supports the use of gemspecs for development. You can change your gemfile to the following:

source "http://www.rubygems.org"

gemspec

This will allow you to access all the gems you would need as a client of the gem you're building. Then in your test file you can just:

require "my_gem"

You can find more information in Yehuda's post.

Upvotes: 1

Related Questions