Merge pull request #7205 from dnkoutso/system_frameworks_test_specs

Do not link system frameworks of test specs to library targets
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b63ccef..5311c77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,10 @@
 
 ##### Bug Fixes
 
+* Do not link system frameworks of test specs to library targets  
+  [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
+  [#7205](https://github.com/CocoaPods/CocoaPods/pull/7205)
+
 * Be more lenient when stripping frameworks and dSYMs for non fat binaries  
   [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
   [#7196](https://github.com/CocoaPods/CocoaPods/issues/7196)
diff --git a/lib/cocoapods/installer/xcode/pods_project_generator.rb b/lib/cocoapods/installer/xcode/pods_project_generator.rb
index ebd3af9..02951f1 100644
--- a/lib/cocoapods/installer/xcode/pods_project_generator.rb
+++ b/lib/cocoapods/installer/xcode/pods_project_generator.rb
@@ -192,13 +192,14 @@
 
         def add_system_framework_dependencies
           # @TODO: Add Specs
-          pod_targets.sort_by(&:name).each do |pod_target|
-            pod_target.file_accessors.each do |file_accessor|
-              file_accessor.spec_consumer.frameworks.each do |framework|
-                if pod_target.should_build?
-                  pod_target.native_target.add_system_framework(framework)
-                end
-              end
+          pod_targets.select(&:should_build?).sort_by(&:name).each do |pod_target|
+            test_file_accessors, file_accessors = pod_target.file_accessors.partition { |fa| fa.spec.test_specification? }
+            file_accessors.each do |file_accessor|
+              add_system_frameworks_to_native_target(file_accessor, pod_target.native_target)
+            end
+            test_file_accessors.each do |test_file_accessor|
+              native_target = pod_target.native_target_for_spec(test_file_accessor.spec)
+              add_system_frameworks_to_native_target(test_file_accessor, native_target)
             end
           end
         end
@@ -315,6 +316,12 @@
           end
         end
 
+        def add_system_frameworks_to_native_target(file_accessor, native_target)
+          file_accessor.spec_consumer.frameworks.each do |framework|
+            native_target.add_system_framework(framework)
+          end
+        end
+
         def add_resource_bundles_to_native_target(dependent_target, native_target)
           resource_bundle_targets = dependent_target.resource_bundle_targets + dependent_target.test_resource_bundle_targets
           resource_bundle_targets.each do |resource_bundle_target|
diff --git a/spec/unit/installer/xcode/pods_project_generator_spec.rb b/spec/unit/installer/xcode/pods_project_generator_spec.rb
index c073ef4..e6cc3b8 100644
--- a/spec/unit/installer/xcode/pods_project_generator_spec.rb
+++ b/spec/unit/installer/xcode/pods_project_generator_spec.rb
@@ -131,6 +131,7 @@
             it 'install the targets of the Pod project' do
               spec = fixture_spec('banana-lib/BananaLib.podspec')
               target_definition = Podfile::TargetDefinition.new(:default, nil)
+              target_definition.set_platform(:ios, '8.0')
               target_definition.abstract = false
               target_definition.store_pod('BananaLib')
               pod_target = PodTarget.new([spec], [target_definition], config.sandbox)
@@ -143,6 +144,7 @@
             it 'does not skip empty pod targets' do
               spec = fixture_spec('banana-lib/BananaLib.podspec')
               target_definition = Podfile::TargetDefinition.new(:default, nil)
+              target_definition.set_platform(:ios, '8.0')
               target_definition.abstract = false
               pod_target = PodTarget.new([spec], [target_definition], config.sandbox)
               @generator.stubs(:aggregate_targets).returns([])