fix tests

This commit is contained in:
John Bintz 2012-06-05 08:20:48 -04:00
parent 47d8d3c52c
commit 033ba8a54c
6 changed files with 57 additions and 26 deletions

View File

@ -40,12 +40,10 @@ Feature: Gemfiles
<% end %>
"""
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
Then the file "Gemfile" should have the following stripped content:
"""
# generated by penchant, environment: local
gem 'test', :path => %{../test}
"""
Scenario: Use a gem list for an operation
@ -58,15 +56,10 @@ Feature: Gemfiles
<% end %>
"""
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
Then the file "Gemfile" should have the following stripped content:
"""
# generated by penchant, environment: local
gem 'test', :path => %{../test}
"""
Scenario: Let gem get additional info
@ -81,6 +74,7 @@ Feature: Gemfiles
"""
# generated by penchant, environment: local
gem 'test', :path => %{../test}
"""

View File

@ -49,6 +49,7 @@ Feature: Gemfiles
gem "three", {:path=>"../three"}
"""
@wip
Scenario: Use an env block
Given I have the file "Gemfile.penchant" with the content:
"""
@ -105,7 +106,6 @@ Feature: Gemfiles
gem "one", {:path=>"../one", :require=>nil}
"""
@wip
Scenario: Don't add an empty hash
Given I have the file "Gemfile.penchant" with the content:
"""
@ -118,3 +118,15 @@ Feature: Gemfiles
gem "one"
"""
Scenario: Single gem gets processed like a gems list
Given I have the file "Gemfile.penchant" with the content:
"""
gem 'one', :path => '../%s'
"""
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"}
"""

View File

@ -0,0 +1,7 @@
Then /^the file "(.*?)" should have the following stripped content:$/ do |file, string|
test_lines = string.lines.to_a
File.read(file).lines.collect(&:strip).reject(&:empty?).to_a.each do |line|
line.strip.should == test_lines.shift.strip
end
end

View File

@ -6,6 +6,7 @@ Before('@fakefs') do
end
After do
FakeFS::FileSystem.clear
FakeFS.deactivate!
FileUtils.rm_rf 'tmp'

View File

@ -100,24 +100,21 @@ module Penchant
end
def gem(*args)
gem_name, template = split_args(args)
options = process_options(gem_name, template)
args = [ gem_name.first ]
args << options if !options.empty?
@output << %{gem #{args_to_string(args)}}
end
def gems(*gems)
template = {}
while gems.last.instance_of?(Hash)
template.merge!(gems.pop)
end
def gems(*args)
gems, template = split_args(args)
gems.flatten.each do |gem_name|
options = Hash[
template.collect { |key, value|
value = value % gem_name if value.respond_to?(:%)
[ key, value ]
}.sort
]
options = process_options(gem_name, template)
args = [ gem_name ]
args << options if !options.empty?
@ -152,6 +149,16 @@ module Penchant
args.inspect[1..-2]
end
def split_args(args)
template = {}
while args.last.instance_of?(Hash)
template.merge!(args.pop)
end
[ args, template ]
end
def call_and_indent_output(block)
index = @output.length
block.call
@ -159,6 +166,16 @@ module Penchant
@output[i] = " " + @output[i]
end
end
def process_options(gem_name, template = {})
Hash[
template.collect { |key, value|
value = value % gem_name if value.respond_to?(:%)
[ key, value ]
}.sort
]
end
end
def switch_to!(gemfile_env = nil, deployment = false)

View File

@ -1,3 +1,3 @@
module Penchant
VERSION = "0.1.2.1"
VERSION = "0.2.0"
end