fix bug in erb processing for env blocks

This commit is contained in:
John Bintz 2012-06-08 15:14:59 -04:00
parent f4cc4ec0a7
commit b3274c7e34
4 changed files with 25 additions and 6 deletions

View File

@ -32,6 +32,19 @@ Feature: Gemfiles
this is content 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 Scenario: Use placeholder expansion
Given I have the file "Gemfile.erb" with the content: Given I have the file "Gemfile.erb" with the content:
""" """
@ -40,10 +53,11 @@ Feature: Gemfiles
<% end %> <% end %>
""" """
When I rebuild the Gemfile for "local" mode When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following stripped content: Then the file "Gemfile" should have the following stripped content:
""" """
# generated by penchant, environment: local # generated by penchant, environment: local
gem 'test', :path => %{../test} gem 'test', {:path=>"../test"}
""" """
Scenario: Use a gem list for an operation Scenario: Use a gem list for an operation
@ -59,7 +73,7 @@ Feature: Gemfiles
Then the file "Gemfile" should have the following stripped content: Then the file "Gemfile" should have the following stripped content:
""" """
# generated by penchant, environment: local # generated by penchant, environment: local
gem 'test', :path => %{../test} gem 'test', {:path=>"../test"}
""" """
Scenario: Let gem get additional info Scenario: Let gem get additional info

View File

@ -173,7 +173,6 @@ Feature: Gemfiles
| cat | | cat |
| dog | | dog |
@wip
Scenario: Get the list of git repos defined Scenario: Get the list of git repos defined
Given I have the file "Gemfile.penchant" with the content: Given I have the file "Gemfile.penchant" with the content:
""" """

View File

@ -181,14 +181,20 @@ module Penchant
end end
def env(check, template = {}, &block) def env(check, template = {}, &block)
if check.to_s == @env.to_s if check.to_s == @environment.to_s
original_erbout = @_erbout.dup original_erbout = @_erbout.dup
output = instance_eval(&block).lines.to_a output = instance_eval(&block).lines.to_a
output.each do |line| output.each do |line|
if gem_name = line[%r{gem ['"]([^'"]+)['"]}, 1] 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
end end

View File

@ -1,3 +1,3 @@
module Penchant module Penchant
VERSION = "0.2.2" VERSION = "0.2.3"
end end