Created
January 14, 2010 17:58
-
-
Save thinkerbot/277349 to your computer and use it in GitHub Desktop.
A bundler+gemspec setup for managing dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |s| | |
s.name = "example" | |
s.version = "0.0.1" | |
s.author = "Your Name Here" | |
s.email = "[email protected]" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################# | |
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require File.expand_path('../../.bundle/environment', __FILE__) | |
rescue LoadError | |
require "rubygems" | |
require "bundler" | |
Bundler.setup | |
end | |
require 'test/unit' |
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!
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
Cool, I like the idea of looking through the gem dependencies and assigning them to a test group