Class: Pod::Command::Lib::Testing
- Inherits:
-
Pod::Command::Lib
- Object
- Pod::Command::Lib
- Pod::Command::Lib::Testing
- Defined in:
- lib/pod/command/lib/testing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #handle_workspace(workspace, workspace_location) ⇒ Object
-
#initialize(argv) ⇒ Testing
constructor
A new instance of Testing.
- #podspecs_to_check ⇒ Object
- #run ⇒ Object
- #run_tests(workspace, target_name, scheme_name) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Testing
Returns a new instance of Testing.
20 21 22 23 24 |
# File 'lib/pod/command/lib/testing.rb', line 20 def initialize(argv) @@verbose = argv.flag?('verbose') @@args = argv.arguments! super end |
Class Method Details
.handle_workspaces_in_dir(dir) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/pod/command/lib/testing.rb', line 26 def self.handle_workspaces_in_dir(dir) workspaces_in_dir(dir).each do |workspace_path| next if workspace_path.end_with?('.xcodeproj') workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path) yield workspace, workspace_path end end |
.options ⇒ Object
14 15 16 17 18 |
# File 'lib/pod/command/lib/testing.rb', line 14 def self. [ ['--verbose', 'Show full xcodebuild output.'] ] end |
.workspaces_in_dir(dir) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/pod/command/lib/testing.rb', line 108 def self.workspaces_in_dir(dir) glob_match = Dir.glob("#{dir}/**/*.xc{odeproj,workspace}") glob_match = glob_match.reject do |p| next true if p.include?('Pods.xcodeproj') next true if p.end_with?('.xcodeproj/project.xcworkspace') sister_workspace = p.chomp(File.extname(p.to_s)) + '.xcworkspace' p.end_with?('.xcodeproj') && glob_match.include?(sister_workspace) end end |
Instance Method Details
#handle_workspace(workspace, workspace_location) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pod/command/lib/testing.rb', line 37 def handle_workspace(workspace, workspace_location) workspace.file_references.each do |ref| if ref.path.end_with?('.xcodeproj') if not File.exists? ref.path next end project = Xcodeproj::Project.open(ref.path) schemes = Dir[Xcodeproj::XCScheme.shared_data_dir(ref.path).to_s + '/*'] schemes += Dir[Xcodeproj::XCScheme.user_data_dir(ref.path).to_s + '/*'] scheme_map = Hash.new schemes.each do |path| doc = REXML::Document.new(File.new(path)) REXML::XPath.each(doc, '//TestAction') do |action| blueprint_name = REXML::XPath.first(action, '//BuildableReference/@BlueprintName').value scheme_name = File.basename(path, '.xcscheme') scheme_map[blueprint_name] = scheme_name end end project.targets.each do |target| product_type = nil begin product_type = target.product_type.to_s rescue next end if product_type.end_with?('bundle.unit-test') scheme = scheme_map[target.name] # Fallback to first scheme if none is found for this target scheme = scheme_map.first[1] unless scheme && scheme.length > 0 run_tests(workspace_location, target.name, scheme) end end end end end |
#podspecs_to_check ⇒ Object
79 80 81 82 83 84 |
# File 'lib/pod/command/lib/testing.rb', line 79 def podspecs_to_check podspecs = Pathname.glob(Pathname.pwd + '*.podspec{.yaml,}') msg = 'Unable to find a podspec in the working directory' fail Informative, msg if podspecs.count.zero? podspecs end |
#run ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pod/command/lib/testing.rb', line 118 def run podspecs_to_check.each do # |path| # TODO: How to link specs to projects/workspaces? # spec = Specification.from_file(path) self.class.handle_workspaces_in_dir(Pathname.pwd) do |workspace, workspace_path| handle_workspace(workspace, workspace_path) end Dir['*'].each do |dir| next if !File.directory?(dir) original_dir = Pathname.pwd Dir.chdir(dir) self.class.handle_workspaces_in_dir(Pathname.pwd) do |workspace, workspace_path| handle_workspace(workspace, workspace_path) end Dir.chdir(original_dir) end end end |
#run_tests(workspace, target_name, scheme_name) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pod/command/lib/testing.rb', line 86 def run_tests(workspace, target_name, scheme_name) # TODO: Figure out what this was supposed to do: # new(test: 'server:autostart') XCTasks::TestTask.new do |t| t.actions = %w(clean build test) t.runner = @@verbose ? :xcodebuild : :xcpretty t.workspace = workspace t.actions << @@args unless @@args.nil? t.subtask(unit: scheme_name) do |s| # TODO: version should be configurable s.ios_versions = %w(7.1) s.destination('name=iPhone Retina (4-inch)') end end UI.puts 'Running tests for ' + target_name # puts Rake.application.tasks Rake::Task['test:unit'].invoke end |