Create a repository for your gem.
You can do this on github, like I did for my gem, locally, or somewhere else.
Create a skeleton gem
The rails guide for creating a plugin has this, but the details in the guide are thin.
This creates a skeleton gem with a dummy rails application you can use for testing your gem.
Rails 3.1 ships with a rails plugin new command which creates a skeleton for developing any kind of Rails extension with the ability to run integration tests using a dummy Rails application.I used this to create a skeleton for my plugin:
This creates a skeleton gem with a dummy rails application you can use for testing your gem.
Switch to rspec
I've used rspec for all my rails testing and I wanted to use it with my new gem as well. However, the generator creates a test-unit dummy application out of the box. This StackOverflow question had a good answer that I used to switch from test-unit to rspec.
- Add rspec as a development dependency in your gemspec
- Bundle Install
- Convert from test-unit to rspec
- Modify spec_helper.rb with code taken from test_helper.rb
- Run the tests
- Commit the skeleton gem to source control
Author your gem
At this point, you have a skeleton gem that you can use to write your code. The gem I wrote added some behavior to ActiveRecord models, so I started out by generating some models in the dummy rails application located in spec/dummy and using test-driven development to build my gem.Try it with a real project
The tests you author along with your gem are very helpful, but a time will come when you want to try your gem on your local file system with a real project. You can include a gem from the local file system with this in your gemfile:
Squash your commits
When you've got your gem working and you are ready to publish it, you may want to squash all your commits to the repository into a single commit.
Take a look at http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html or search the web on how to squash multiple commits to a single commit, or try it with git rebase -i
Having require 'scratch' in spec_helper.rb does not seem necessary.
ReplyDelete