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”.
$ bundle gem wozziegoggle
# wozziegoggle.gemspec
Gem::Specification.new do |s|
...
s.add_development_dependency 'rspec', '~>2.6.0'
s.add_development_dependency 'mocha', '~>0.9.12'
end
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'))
$:.unshift(lib_dir)
$:.uniq!
RSpec.configure do |config|
config.mock_with :mocha
end
require 'mocha'
require 'wozziegoggle'
Rakefile. I’ll also add a task which spawns IRB with the gem libraries preloaded.# Rakefile
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :default => :spec
desc 'Start IRB with preloaded environment'
task :console do
exec 'irb', "-I#{File.join(File.dirname(__FILE__), 'lib')}", '-rwozziegoggle'
end
autotest 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'}
.rspec (née spec/spec.opts) file with any options I want rspec to be run with.# .rspec
--colour
© 2012 John Parker | Valid XHTML 1.0 Strict | Valid CSS 2.1