Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop Gems?

I would like to write my own gem that helps me in my rails apps. It will also inculde some controllers that deliver html. So i need to test that in a browser (html/css/js).

Whats the best practice for that?

Now im using the echoe gem to build my gem (are there any better gems?). rake install switch to other tab stop the rails app start the rails app (so it has loaded the gem) and then testing it, in a browser with good old refresh.

This is no fun. Can i do it more efficient somehow? Is it insane not to write tests for the ruby files?

like image 587
antpaw Avatar asked Jan 10 '11 17:01

antpaw


People also ask

How do I publish a ruby gem?

The simplest way to distribute a gem for public consumption is to use RubyGems.org. Gems that are published to RubyGems.org can be installed via the gem install command or through the use of tools such as Isolate or Bundler.


2 Answers

You could use two resources to help you:

https://github.com/krschacht/rails_3_engine_demo

https://github.com/josevalim/enginex

This will help you creating a gem which will basically be an engine (enabling controller and views). The first link as great and helpful documentation.

The main principle is to code in a separate folder and add your 'gem' in local by doing gem ‘cheese’, :path => "../rails_3_engine_demo"

Once you feel ready, pack it with jeweller or bundler. Here is another link: http://sirupsen.com/create-your-first-ruby-gem-and-release-it-to-gemcutter//

Including the gem this way in your app will enable you to properly test it's behaviour.

like image 136
apneadiving Avatar answered Oct 06 '22 04:10

apneadiving


jeweler:Opinionated tool for creating and managing Rubygem projects

like image 27
zengr Avatar answered Oct 06 '22 06:10

zengr