Module: CocoapodsUnitTest

Defined in:
lib/cocoapods_plugin.rb,
lib/cocoapods-unit-test/gem_version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.modify_build_settings(target, is_target) ⇒ Object



13
14
15
16
17
18
# File 'lib/cocoapods_plugin.rb', line 13

def self.modify_build_settings(target, is_target)
  target.build_configurations.each {|config| config.coverage_build_settings = is_target}
  if is_target
    target.add_coverage_script_phase()
  end
end

.modify_schemes_settings(xcproj, test_specs) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cocoapods_plugin.rb', line 20

def self.modify_schemes_settings(xcproj, test_specs)
  project_path = xcproj.path
  test_targets = xcproj.targets.select { |target| test_specs.include?(target.name.to_s) }

  Dir[File.join(project_path, 'xcuserdata', '**', 'xcschemes', '*.xcscheme')].select { |e| 
    !test_targets.select { |target|
      File.basename(e, '.xcscheme').start_with?("#{target.name.to_s}-Unit") 
    }.empty?
  }.each do |path|
    scheme = File.basename(path, '.xcscheme')
    puts "Check scheme: #{scheme}"
    scheme_targets = test_targets.select { |e| scheme.include?(e.name.to_s) }
    unless scheme_targets.empty?
      puts "Test scheme: #{scheme} with targets: " + scheme_targets.map { |e| e.name.to_s }.join(",")
      xcproj_scheme = Xcodeproj::XCScheme.new(file_path = path)
      testAction = xcproj_scheme.test_action
      testAction.code_coverage_enabled = true
      testAction.coverage_specified_targets = true
      scheme_targets.each { |e| testAction.add_coverage_target(e) }
      # xcproj_scheme.save!
      File.delete(path)
      xcproj_scheme.save_as(project_path, scheme)
    else
      File.delete(path)
    end
  end
end