From 55e31dd47face2e42446ca4037573da7c92336db Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 4 Oct 2012 10:43:38 -0400 Subject: [PATCH] fix a bug with command order --- features/ruby_gemfile.feature | 30 ++++++++++++++++++++++++++++++ lib/penchant/gemfile.rb | 5 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index 3ea622b..291ff4d 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -322,6 +322,36 @@ Feature: Gemfiles gem "two", {:require=>nil} """ + Scenario: Define a pair of opposites in the other order + Given I have the file "Gemfile.penchant" with the content: + """ + opposites :local, :remote + defaults_for env(:local), :path => '../%s' + + property(:github) { |name| { :git => "git://github.com/#{name}/%s.git" } } + + env :remote do + gem 'one', :github => 'johnbintz', :require => nil + end + env :local do + gem 'two', :path => '../%s', :require => nil + end + """ + When I rebuild the Gemfile for "local" mode + Then the file "Gemfile" should have the following content: + """ + # generated by penchant, environment: local + gem "one", {:path=>"../one", :require=>nil} + gem "two", {:path=>"../two", :require=>nil} + """ + When I rebuild the Gemfile for "remote" mode + Then the file "Gemfile" should have the following content: + """ + # generated by penchant, environment: remote + gem "one", {:git=>"git://github.com/johnbintz/one.git", :require=>nil} + gem "two", {:require=>nil} + """ + Scenario: Override defaults for an environment Given I have the file "Gemfile.penchant" with the content: """ diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 970ed94..ead4c1c 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -197,7 +197,10 @@ module Penchant def defaults_for(*args) defaults = args.pop - args.flatten.each { |gem| @defaults[gem.to_s] = defaults.dup } + args.flatten.each do |gem| + @defaults[gem.to_s] ||= {} + @defaults[gem.to_s].merge!(defaults) + end end protected