Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created January 14, 2010 17:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/277349 to your computer and use it in GitHub Desktop.
Save thinkerbot/277349 to your computer and use it in GitHub Desktop.
A bundler+gemspec setup for managing dependencies
Gem::Specification.new do |s|
s.name = "example"
s.version = "0.0.1"
s.author = "Your Name Here"
s.email = "your.email@pubfactory.edu"
s.homepage = ""
s.platform = Gem::Platform::RUBY
s.summary = ""
s.require_path = "lib"
s.rubyforge_project = ""
# add dependencies
s.add_dependency("sinatra")
s.add_development_dependency("rack-test")
s.has_rdoc = true
s.rdoc_options.concat %W{--main README -S -N --title Example}
# list extra rdoc files
s.extra_rdoc_files = %W{
}
# list the files you want to include
s.files = %W{
}
end
require File.expand_path('../test_helper', __FILE__)
require 'sinatra'
require 'rack/test'
class ExampleTest < Test::Unit::TestCase
def test_all_the_dependencies_are_available
assert true, 'the requires would have failed if not'
end
end
#############################################################################
# Dependencies in this Gemfile are managed through the gemspec. Add/remove
# depenencies there, rather than editing this file ex:
#
# Gem::Specification.new do |s|
# ...
# s.add_dependency("sinatra")
# s.add_development_dependency("rack-test")
# end
#
#############################################################################
source :gemcutter
project_dir = File.expand_path('..', __FILE__)
gemspec_path = File.expand_path('example.gemspec', project_dir)
#
# Setup gemspec dependencies
#
gemspec = eval(File.read(gemspec_path))
gemspec.dependencies.each do |dep|
group = dep.type == :development ? :development : :default
gem dep.name, dep.requirement, :group => group
end
gem(gemspec.name, gemspec.version, :path => project_dir)
require 'rake'
#
# Dependency tasks
#
desc 'Bundle dependencies'
task :bundle do
output = `bundle check 2>&1`
unless $?.to_i == 0
puts output
sh "bundle install"
puts
end
end
#
# Test tasks
#
desc 'Default: Run tests.'
task :default => :test
desc 'Run the tests'
task :test => :bundle do
tests = Dir.glob('test/**/*_test.rb')
sh('ruby', '-w', '-e', 'ARGV.dup.each {|test| load test}', *tests)
end
begin
require File.expand_path('../../.bundle/environment', __FILE__)
rescue LoadError
require "rubygems"
require "bundler"
Bundler.setup
end
require 'test/unit'
@erithmetic
Copy link

Cool, I like the idea of looking through the gem dependencies and assigning them to a test group

@indirect
Copy link

indirect commented Oct 1, 2010

Please don't use this Gemfile. Bundler has the ability to read gemspecs built in. Documentation is at http://gembundler.com/rubygems.html. There's also an (as yet incomplete) guide to gem development with Bundler at http://github.com/radar/guides/blob/master/gem-development.md. Hope that helps!

@thinkerbot
Copy link
Author

Thanks for the tip! I started using this system before the built-in support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment