From 033ba8a54c3a343b8e37ff1f636e2fcedacb388d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 5 Jun 2012 08:20:48 -0400 Subject: [PATCH] fix tests --- features/gemfile.feature | 16 +++---- features/ruby_gemfile.feature | 14 +++++- ...uld_have_the_following_stripped_content.rb | 7 +++ features/support/env.rb | 1 + lib/penchant/gemfile.rb | 43 +++++++++++++------ lib/penchant/version.rb | 2 +- 6 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb diff --git a/features/gemfile.feature b/features/gemfile.feature index af6e01f..890cf84 100644 --- a/features/gemfile.feature +++ b/features/gemfile.feature @@ -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} - + 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} - - + 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} """ diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index f7372d5..da0460a 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -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"} + """ + diff --git a/features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb b/features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb new file mode 100644 index 0000000..8bee548 --- /dev/null +++ b/features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb @@ -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 diff --git a/features/support/env.rb b/features/support/env.rb index 3342870..caee814 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -6,6 +6,7 @@ Before('@fakefs') do end After do + FakeFS::FileSystem.clear FakeFS.deactivate! FileUtils.rm_rf 'tmp' diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 97f7a09..96ac61b 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -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) diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index b545099..1ec78cd 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.1.2.1" + VERSION = "0.2.0" end