6

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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
antpaw
  • 15,444
  • 11
  • 59
  • 88
  • Would probably be a good idea to do most of your work in your unit tests, then check that behavior on the live app once you're reasonably confident that it will work. – Matchu Jan 10 '11 at 17:38
  • yes of couse, but thats not how i write the frontend stuff. i usually test every line of code i wrote with a refresh. – antpaw Jan 10 '11 at 17:42
  • 1
    try Bundler? http://railscasts.com/episodes/245-new-gem-with-bundler – fl00r Jan 10 '11 at 18:57
  • 1
    possible duplicate of [Ruby : How to write a gem ?](http://stackoverflow.com/questions/2194547/ruby-how-to-write-a-gem) – Andrew Grimm Jan 10 '11 at 22:32

2 Answers2

7

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.

apneadiving
  • 114,565
  • 26
  • 219
  • 213
3

jeweler:Opinionated tool for creating and managing Rubygem projects

zengr
  • 38,346
  • 37
  • 130
  • 192