These are the steps I currently follow when starting a new project to be distributed as a RubyGem. Let’s assume the new RubyGem will be named “wozziegoggle”.

Bootstrap the project using Bundler:

$ bundle gem wozziegoggle

I’m using RSpec and Mocha on new projects, so I add development gem dependencies for each.

# wozziegoggle.gemspec do |s|
  # …
  s.add_development_dependency 'rspec', '~>2.6.0'
  s.add_development_dependency 'mocha', '~>0.9.12'

I also create a basic spec_helper.rb file that configures RSpec and requires needed libraries.

# spec/spec_helper.rb
spec_dir = File.dirname(__FILE__)
lib_dir  = File.expand_path(File.join(spec_dir, '..', 'lib'))
RSpec.configure do |config|
  config.mock_with :mocha
require 'mocha'
require 'wozziegoggle'

The RSpec rake taks will also be needed, so I make changes to the Rakefile. I’ll also add a task which spawns IRB with the gem libraries preloaded.

# Rakefile
require 'rspec/core/rake_task'
task :default => :spec
desc 'Start IRB with preloaded environment'
task :console do
  exec 'irb', "-I#{File.join(File.dirname(__FILE__), 'lib')}", '-rwozziegoggle'

I usually use ZenTest, specifically autotest</ttt> so that the specs can by automatically re-run as I’m developing. A discover file is needed to make sure there are sane default mappings.

# autotest/discover.rb
Autotest.add_discover {'rspec2'}

Finally, I’ll create a .rspec (née spec/spec.opts) file with any options I want rspec to be run with.

# .rspec