From b3274c7e34d63a7e542c0f669d7bd9fddee9a29f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 8 Jun 2012 15:14:59 -0400 Subject: [PATCH] fix bug in erb processing for env blocks --- features/gemfile.feature | 18 ++++++++++++++++-- features/ruby_gemfile.feature | 1 - lib/penchant/gemfile.rb | 10 ++++++++-- lib/penchant/version.rb | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/features/gemfile.feature b/features/gemfile.feature index 290db10..ac6d788 100644 --- a/features/gemfile.feature +++ b/features/gemfile.feature @@ -32,6 +32,19 @@ Feature: Gemfiles this is content """ + Scenario: Simple env + Given I have the file "Gemfile.erb" with the content: + """ + <% env :local do %> + gem 'test' + <% end %> + """ + When I rebuild the Gemfile for "local" mode + Then the file "Gemfile" should have the following stripped content: + """ + # generated by penchant, environment: local + gem 'test' + """ Scenario: Use placeholder expansion Given I have the file "Gemfile.erb" with the content: """ @@ -40,10 +53,11 @@ Feature: Gemfiles <% end %> """ When I rebuild the Gemfile for "local" mode + Then the file "Gemfile" should have the following stripped content: """ # generated by penchant, environment: local - gem 'test', :path => %{../test} + gem 'test', {:path=>"../test"} """ Scenario: Use a gem list for an operation @@ -59,7 +73,7 @@ Feature: Gemfiles Then the file "Gemfile" should have the following stripped content: """ # generated by penchant, environment: local - gem 'test', :path => %{../test} + gem 'test', {:path=>"../test"} """ Scenario: Let gem get additional info diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index a41b0bd..5234470 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -173,7 +173,6 @@ Feature: Gemfiles | cat | | dog | - @wip Scenario: Get the list of git repos defined Given I have the file "Gemfile.penchant" with the content: """ diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 7082c51..8fe9d35 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -181,14 +181,20 @@ module Penchant end def env(check, template = {}, &block) - if check.to_s == @env.to_s + if check.to_s == @environment.to_s original_erbout = @_erbout.dup output = instance_eval(&block).lines.to_a output.each do |line| if gem_name = line[%r{gem ['"]([^'"]+)['"]}, 1] - line.replace(line.rstrip + process_options(gem_name, template) + "\n") + new_line = line.rstrip + + if !(options = process_options(gem_name, template)).empty? + new_line += ", #{options.inspect}" + end + + line.replace(new_line + "\n") end end diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index fee3a95..0254e7d 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.2" + VERSION = "0.2.3" end