diff options
author | Joshua Hull <joshbuddy@gmail.com> | 2010-06-23 23:43:49 -0400 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2010-06-23 21:09:16 -0700 |
commit | da2d4555fc5cfffafde38118b23332a4dab9520f (patch) | |
tree | 3b297a21aa003bcc923ef8530fd6e3a051dc3082 | |
parent | 96a1acf1df5ac72bb0a739f9f8de4b1af1cc2f0f (diff) | |
download | bundler-da2d4555fc5cfffafde38118b23332a4dab9520f.tar.gz |
added gemspec command to dsl to allow importing of gemspecs
-rw-r--r-- | lib/bundler/dsl.rb | 23 | ||||
-rw-r--r-- | spec/install/gemspec_spec.rb | 80 |
2 files changed, 103 insertions, 0 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index cbfa3142b7..c7e6dedb45 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -20,6 +20,29 @@ module Bundler @env = nil end + def gemspec(opts) + path = opts[:path] || '.' + name = opts[:name] || '*' + development_group = opts[:development_group] || :developement + gemspecs = Dir[File.join(path, "#{name}.gemspec")] + case gemspecs.size + when 1 + spec = Gem::Specification.load(gemspecs.first) + spec.runtime_dependencies.each do |dep| + gem dep.name, dep.requirement.to_s + end + group(development_group) do + spec.development_dependencies.each do |dep| + gem dep.name, dep.requirement.to_s + end + end + when 0 + raise InvalidOption, "There are no gemspecs at #{path}." + else + raise InvalidOption, "There are multiple gemspecs at #{path}. Please use the :name option to specify which one." + end + end + def gem(name, *args) options = Hash === args.last ? args.pop : {} version = args.last || ">= 0" diff --git a/spec/install/gemspec_spec.rb b/spec/install/gemspec_spec.rb new file mode 100644 index 0000000000..db85e3d6c5 --- /dev/null +++ b/spec/install/gemspec_spec.rb @@ -0,0 +1,80 @@ +require "spec_helper" + +describe "bundle install from an existing gemspec" do + + before(:each) do + build_gem "bar", :to_system => true + build_gem "bar-dev", :to_system => true + end + + it "should install runtime and development dependecies" do + build_lib("foo", :path => tmp.join("foo")) do |s| + s.write("Gemfile", "source :rubygems\ngemspec") + s.add_dependency "bar", "=1.0.0" + s.add_development_dependency "bar-dev", '=1.0.0' + end + install_gemfile <<-G + source "file://#{gem_repo2}" + gemspec :path => '#{tmp.join("foo")}' + G + + should_be_installed "bar 1.0.0" + should_be_installed "bar-dev 1.0.0", :groups => :development + end + + it "should raise if there are no gemspecs available" do + build_lib("foo", :path => tmp.join("foo"), :gemspec => false) + + error = install_gemfile(<<-G, :expect_err => true) + source "file://#{gem_repo2}" + gemspec :path => '#{tmp.join("foo")}' + G + error.should match(/There are no gemspecs at #{tmp.join('foo')}/) + end + + it "should raise if there are too many gemspecs available" do + build_lib("foo", :path => tmp.join("foo")) do |s| + s.write("foo2.gemspec", "") + end + + error = install_gemfile(<<-G, :expect_err => true) + source "file://#{gem_repo2}" + gemspec :path => '#{tmp.join("foo")}' + G + error.should match(/There are multiple gemspecs at #{tmp.join('foo')}/) + end + + it "should pick a specific gemspec" do + build_lib("foo", :path => tmp.join("foo")) do |s| + s.write("foo2.gemspec", "") + s.add_dependency "bar", "=1.0.0" + s.add_development_dependency "bar-dev", '=1.0.0' + end + + install_gemfile(<<-G, :expect_err => true) + source "file://#{gem_repo2}" + gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + G + + should_be_installed "bar 1.0.0" + should_be_installed "bar-dev 1.0.0" + end + + it "should use a specific group for development dependencies" do + build_lib("foo", :path => tmp.join("foo")) do |s| + s.write("foo2.gemspec", "") + s.add_dependency "bar", "=1.0.0" + s.add_development_dependency "bar-dev", '=1.0.0', :groups => :development + end + + install_gemfile(<<-G, :expect_err => true) + source "file://#{gem_repo2}" + gemspec :path => '#{tmp.join("foo")}', :name => 'foo', :development_group => :dev + G + + should_be_installed "bar 1.0.0" + should_not_be_installed "bar-dev 1.0.0", :groups => :development + should_be_installed "bar-dev 1.0.0", :groups => :dev + end + +end |