Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing gems and testing

I am new to developing Ruby gems, but I thought I'd give it a try.

Recently checking out the latest episode on Railscasts (http://railscasts.com/episodes/245-new-gem-with-bundler) I'm using Bundler to create my gem.

However I'm kind of clueless on how to test my gem.

Sure I could run rake install and then require it from irb, but this seems like a kind of slow workflow for me.

What I'd like to do is create a dummy Rails app and require the gem by referencing to it's source code. Is this possible? I'm sure I've read about it somewhere…

Thanks!

like image 629
Erik Avatar asked Dec 20 '10 19:12

Erik


2 Answers

You can include these lines in your Rakefile:

task :console do   exec "irb -r mygem -I ./lib" end 

This will create a rake task to initialize a new irb session and preload your library. Now, all you have to do is:

$ rake console 
like image 102
Javier Vidal Avatar answered Sep 25 '22 17:09

Javier Vidal


I can't recommend this guide from Ryan Bigg enough: http://bundler.io/v1.16/guides/creating_gem.html. It walks you through generating a gem using Bundler and setting up automated testing. You can develop your features without ever actually having to run your code manually. It's a workflow I'm using for my own gem development and has worked very well so far.

UPDATE: Rereading your question, it sounds like your gem is a Rails engine. I'd recommending looking at José Valim's EngineX. It's a generator that creates a gem with a dummy Rails app for testing (https://github.com/josevalim/enginex). If you already have a lot of code, http://keithschacht.com/creating-a-rails-3-engine-plugin-gem/ might help you setup a dummy app for testing.

like image 35
Joe Fiorini Avatar answered Sep 23 '22 17:09

Joe Fiorini