class Pod::TestProject
Attributes
cov_shell[RW]
derived_data_path[RW]
destination[RW]
path[RW]
podfile[RW]
pods_project[RW]
schemes[RW]
target[RW]
workspace[RW]
Public Class Methods
new(name, simulator, path = Dir.pwd)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 19 def initialize(name, simulator, path = Dir.pwd) @destination = "platform=iOS Simulator,name=#{simulator}" @target = name @path = File.expand_path(path) end
Public Instance Methods
archives_path(scheme)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 82 def archives_path(scheme) File.expand_path("build/#{scheme}/archives", path) end
pod_install()
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 96 def pod_install UI.puts "pod install..." raise Informative, "Please use a Gemfile or run pod install by yourself" unless File.file?("Gemfile") system( "bundle install") system( "bundle exec pod install") raise Informative, "XcodeCoverage not found" unless File.file?(cov_shell) raise Informative, "workspace not found" unless File.directory?(workspace) end
result_bundle_path(scheme)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 70 def result_bundle_path(scheme) File.expand_path("build/#{scheme}/Test.xcresult", path) end
result_json_path(scheme)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 74 def result_json_path(scheme) File.expand_path("build/#{scheme}/TestResult.json", path) end
run(install_flag)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 151 def run(install_flag) pod_install if install_flag run_test end
run_test()
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 136 def run_test UI.title "Test target: #{target}" do schemes.each { |e| UI.puts "Test Schemes: #{e}" } end system( "rm -fr #{derived_data_path}") system( "mkdir -p #{derived_data_path}") schemes.each do |scheme| UI.puts "Testing #{scheme}..." run_test_with_scheme(scheme) end end
run_test_with_scheme(scheme)
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 105 def run_test_with_scheme(scheme) system("rm -fr #{result_bundle_path(scheme)}") system("rm -fr #{result_json_path(scheme)}") system("rm -fr #{archives_path(scheme)}") system("mkdir -p #{archives_path(scheme)}") cmd = %W(xcodebuild test -workspace #{workspace} -scheme #{scheme} -UseModernBuildSystem=NO -derivedDataPath #{derived_data_path} -resultBundlePath #{result_bundle_path(scheme)}) + [ "-destination '#{destination}'", "| xcpretty", ] UI.puts cmd.join(" ") system(cmd.join(" ")) cmd = %W(xcrun xcresulttool get --path #{result_bundle_path(scheme)} --format json) + [ "> #{result_json_path(scheme)}", ] UI.puts cmd.join(" ") system(cmd.join(" ")) cmd = %W(#{cov_shell} -x -o #{archives_path(scheme)}) UI.puts cmd.join(" ") system(cmd.join(" ")) index_file = File.join(archives_path(scheme),"lcov/index.html") TestResult.new(result_json_path(scheme),index_file).parse() UI.puts "Test result path #{index_file}" system("open #{index_file}") if File.file?(index_file) end
validate!()
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 90 def validate! raise Informative, "No Podfile!" unless File.file?(podfile) validate_target! raise Informative, "No Test schemes!" if schemes.empty? end
validate_target!()
click to toggle source
# File lib/cocoapods-unit-test/project.rb, line 58 def validate_target! project = Xcodeproj::Project.open(pods_project) return true if project.unit_test_dev_pods().include?(@target) return true if project.unit_test_dependency_pods().include?(@target) raise Informative, "can not find test target #{@target} in Pods.xcodeproj" return false end