Permalink
Browse files

+ xcode config spec

  • Loading branch information...
1 parent d1ba2e8 commit 3655f6e584aaa01efb1dac6985ecfaa16888172e @alloy alloy committed Sep 16, 2011
Showing with 43 additions and 5 deletions.
  1. +9 −5 lib/cocoa_pods/xcode/config.rb
  2. +34 −0 spec/unit/xcode/config_spec.rb
@@ -6,6 +6,10 @@ def initialize(xcconfig_hash = {})
merge!(xcconfig_hash)
end
+ def to_hash
+ @attributes
+ end
+
def merge!(xcconfig_hash)
xcconfig_hash.each do |key, value|
if existing_value = @attributes[key]
@@ -17,12 +21,12 @@ def merge!(xcconfig_hash)
end
alias_method :<<, :merge!
+ def to_s
+ @attributes.map { |key, value| "#{key} = #{value}" }.join("\n")
+ end
+
def create_in(pods_root)
- (pods_root + 'Pods.xcconfig').open('w') do |file|
- @attributes.each do |key, value|
- file.puts "#{key} = #{value}"
- end
- end
+ (pods_root + 'Pods.xcconfig').open('w') { |file| file << to_s }
end
end
end
@@ -0,0 +1,34 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Pod::Xcode::Config" do
+ extend SpecHelper::TemporaryDirectory
+
+ before do
+ @config = Pod::Xcode::Config.new('OTHER_LD_FLAGS' => '-framework Foundation')
+ end
+
+ it "merges another config hash in place" do
+ @config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
+ @config.to_hash.should == {
+ 'OTHER_LD_FLAGS' => '-framework Foundation',
+ 'HEADER_SEARCH_PATHS' => '/some/path'
+ }
+ end
+
+ it "appends a value for the same key when merging" do
+ @config.merge!('OTHER_LD_FLAGS' => '-l xml2.2.7.3')
+ @config.to_hash.should == {
+ 'OTHER_LD_FLAGS' => '-framework Foundation -l xml2.2.7.3'
+ }
+ end
+
+ it "creates the config file" do
+ @config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
+ @config.merge!('OTHER_LD_FLAGS' => '-l xml2.2.7.3')
+ @config.create_in(temporary_directory)
+ (temporary_directory + 'Pods.xcconfig').read.split("\n").sort.should == [
+ "OTHER_LD_FLAGS = -framework Foundation -l xml2.2.7.3",
+ "HEADER_SEARCH_PATHS = /some/path"
+ ].sort
+ end
+end

0 comments on commit 3655f6e

Please sign in to comment.