diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-01-28 13:57:25 -0800 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-01-28 13:57:35 -0800 |
commit | 5921d93a4ed7b2dd2958cbd2720ae1079362c50c (patch) | |
tree | bd99b7c2440f3cd1afdf36e0f79f970f75f0514b | |
parent | 6e54a209c5e6327cb002857832dcd0860e8c4ca0 (diff) | |
download | bundler-5921d93a4ed7b2dd2958cbd2720ae1079362c50c.tar.gz |
Start work on groups
-rw-r--r-- | lib/bundler/dependency.rb | 8 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 16 | ||||
-rw-r--r-- | spec/install/gems_spec.rb | 16 | ||||
-rw-r--r-- | spec/support/helpers.rb | 6 | ||||
-rw-r--r-- | spec/support/matchers.rb | 8 |
5 files changed, 46 insertions, 8 deletions
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 47ffe68506..21ebd82843 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -2,14 +2,12 @@ require 'rubygems/dependency' module Bundler class Dependency < Gem::Dependency - attr_accessor :source + attr_accessor :source, :group def initialize(name, version, options = {}, &blk) - options.each do |k, v| - options[k.to_s] = v - end - super(name, version) + + @group = options[:group] end end end
\ No newline at end of file diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index a8b529c8a0..feedfda8f9 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -13,12 +13,21 @@ module Bundler @dependencies = [] @git = nil @git_sources = {} + @group = nil end def gem(name, *args) options = Hash === args.last ? args.pop : {} version = args.last || ">= 0" + # Normalize the options + options.each do |k, v| + options[k.to_s] = v + end + + # Set defaults + options["group"] ||= @group + @dependencies << Dependency.new(name, version, options) end @@ -44,5 +53,12 @@ module Bundler Definition.new(@dependencies, @sources) end + def group(name, options = {}, &blk) + old, @group = @group, name + yield + ensure + @group = old + end + end end
\ No newline at end of file diff --git a/spec/install/gems_spec.rb b/spec/install/gems_spec.rb index fa7fc7b56a..bf2d2d8b0e 100644 --- a/spec/install/gems_spec.rb +++ b/spec/install/gems_spec.rb @@ -133,7 +133,6 @@ describe "gemfile install with gem sources" do end describe "when locked" do - it "works" do system_gems "rack-1.0.0" do gemfile <<-G @@ -170,4 +169,19 @@ describe "gemfile install with gem sources" do should_be_installed "rack 1.0.0" end end + + describe "when excluding groups" do + it "does not install gems from the excluded group" do + install_gemfile <<-G, 'without' => 'emo' + source "file://#{gem_repo1}" + gem "rack" + group :emo do + gem "activesupport", "2.3.5" + end + G + + should_be_installed "rack 1.0.0" + should_not_be_installed "activesupport 2.3.5" + end + end end
\ No newline at end of file diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 8d0c4c37ed..0f672364fd 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -36,9 +36,10 @@ module Spec File.expand_path('../../../lib', __FILE__) end - def bundle(cmd) + def bundle(cmd, options = {}) + args = options.map { |k,v| " --#{k} #{v}"}.join gemfile = File.expand_path('../../../bin/bundle', __FILE__) - @out = %x{#{Gem.ruby} -I#{lib} #{gemfile} #{cmd}}.strip + @out = %x{#{Gem.ruby} -I#{lib} #{gemfile} #{cmd}#{args}}.strip end def ruby(opts, ruby = nil) @@ -60,6 +61,7 @@ module Spec def install_gemfile(*args) gemfile(*args) + opts = args.last.is_a?(Hash) ? args.last : {} bundle :install end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index ae145aede6..91ec143263 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -24,5 +24,13 @@ module Spec end alias should_be_available should_be_installed + + def should_not_be_installed(*names) + names.each do |name| + name, version = name.split(/\s+/) + run "require '#{name}'; puts #{Spec::Builders.constantize(name)}" + Gem::Version.new(out).should_not == Gem::Version.new(version) + end + end end end
\ No newline at end of file |