From 4d2137ab5d8a7f07fe553fc5a8c5652030adc8f1 Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Tue, 8 May 2018 08:17:10 +0200 Subject: [PATCH] Spec: run tests against connected physical devices --- spec/clear_app_data_spec.rb | 196 +++++++++++---------- spec/device_app_life_cycle_spec.rb | 274 ++++++++++++++++------------- spec/is_installed_spec.rb | 60 ++++--- spec/resources.rb | 101 ++--------- spec/resources_spec.rb | 65 ------- spec/upload-xcappdata_spec.rb | 85 +++++---- 6 files changed, 363 insertions(+), 418 deletions(-) delete mode 100644 spec/resources_spec.rb diff --git a/spec/clear_app_data_spec.rb b/spec/clear_app_data_spec.rb index ad07d195..2f7e2706 100644 --- a/spec/clear_app_data_spec.rb +++ b/spec/clear_app_data_spec.rb @@ -7,7 +7,7 @@ def self.is_installed?(udid, bundle_id) hash = IDM.shell(args) if hash[:exit_status] == IDM.exit_status(:success) || - hash[:exit_status] == IDM.exit_status(:false) + hash[:exit_status] == IDM.exit_status(:false) hash[:out].split($-0).last == "true" else raise "Expected is-installed to pass: #{hash[:out]}" @@ -55,99 +55,113 @@ def self.collect_cache_files_in_xcappdata(path) end end -describe "clear-app-data command" do - if IDM::Resources.instance.physical_device_attached? - context "physical devices" do - let (:device) { IDM::Resources.instance.default_physical_device } - let (:udid) { device.udid } - let (:app) do - path = IDM::Resources.instance - .test_app(device.physical_device? ? :arm : :x86) - RunLoop::App.new(path) - end - let(:xcappdata) { IDM::Resources.instance.xcappdata } - - before(:each) do |test| - path = IDM::Resources.instance.tmp_dir("xcappdata") - FileUtils.rm_rf(path) - DeviceAppHelper.install(udid, app.path) - end - - it "fails if app isn't installed" do - args = ["clear-app-data", "com.apple.NoSuchApp", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:false) - end - - it "replaces .xcappdata bundle with an empty one" do - original_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Original.xcappdata") - uploaded_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Uploaded.xcappdata") - cleared_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Cleared.xcappdata") - - args = ["download-xcappdata", app.bundle_identifier, original_data_path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - original_data = DeviceAppHelper.collect_files_in_xcappdata(original_data_path) - - args = ["upload-xcappdata", app.bundle_identifier, xcappdata, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["download-xcappdata", app.bundle_identifier, uploaded_data_path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - uploaded_data = DeviceAppHelper.collect_files_in_xcappdata(uploaded_data_path) - expect(uploaded_data - original_data).not_to be_empty - - args = ["clear-app-data", app.path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["download-xcappdata", app.bundle_identifier, cleared_data_path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - cleared_data = DeviceAppHelper.collect_files_in_xcappdata(cleared_data_path) - expect(cleared_data - original_data).to be_empty - end - - it "doesn't change caches" do - original_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Original.xcappdata") - uploaded_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Uploaded.xcappdata") - - args = ["download-xcappdata", app.bundle_identifier, original_data_path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - original_caches = DeviceAppHelper.collect_cache_files_in_xcappdata(original_data_path) - - args = ["clear-app-data", app.bundle_identifier, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["upload-xcappdata", app.bundle_identifier, xcappdata, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["download-xcappdata", app.bundle_identifier, uploaded_data_path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - uploaded_caches = DeviceAppHelper.collect_cache_files_in_xcappdata(uploaded_data_path) - expect(uploaded_caches - original_caches).to be_empty - end - - it "works when first argument is an application path" do - args = ["clear-app-data", app.path, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - end - - it "works when first argument is a bundle identifier" do - args = ["clear-app-data", app.bundle_identifier, udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) +context "clear-app-data command" do + context "physical devices" do + IDM::Resources.instance.xcode_install_paths.each do |developer_dir| + IDM::Resources.instance.with_developer_dir(developer_dir) do + # Add a simulator to this list of of devices + devices = IDM::Resources.instance.physical_devices + xcode_version = developer_dir[/(\d+\.\d+(\.\d+)?)/] + if devices.empty? + it "Xcode #{xcode_version} no compatible devices connected via USB" do + expect(true).to be_truthy + end + else + context "#{developer_dir}" do + let(:app) { RunLoop::App.new(IDM::Resources.instance.test_app(:arm)) } + # For every connected (compatible) device + devices.each do |device| + context "#{device.name} (#{device.version.to_s})" do + # Run these tests + let (:udid) { device.udid } + let(:xcappdata) { IDM::Resources.instance.xcappdata } + + before(:each) do + path = IDM::Resources.instance.tmp_dir("xcappdata") + FileUtils.rm_rf(path) + DeviceAppHelper.install(udid, app.path) + end + + it "fails if app isn't installed" do + args = ["clear-app-data", "com.apple.NoSuchApp", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:false) + end + + it "replaces .xcappdata bundle with an empty one" do + original_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Original.xcappdata") + uploaded_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Uploaded.xcappdata") + cleared_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Cleared.xcappdata") + + args = ["download-xcappdata", app.bundle_identifier, original_data_path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + original_data = DeviceAppHelper.collect_files_in_xcappdata(original_data_path) + + args = ["upload-xcappdata", app.bundle_identifier, xcappdata, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["download-xcappdata", app.bundle_identifier, uploaded_data_path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + uploaded_data = DeviceAppHelper.collect_files_in_xcappdata(uploaded_data_path) + expect(uploaded_data - original_data).not_to be_empty + + args = ["clear-app-data", app.path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["download-xcappdata", app.bundle_identifier, cleared_data_path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + cleared_data = DeviceAppHelper.collect_files_in_xcappdata(cleared_data_path) + expect(cleared_data - original_data).to be_empty + end + + it "doesn't change caches" do + original_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Original.xcappdata") + uploaded_data_path = IDM::Resources.instance.tmp_dir("xcappdata/Uploaded.xcappdata") + + args = ["download-xcappdata", app.bundle_identifier, original_data_path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + original_caches = DeviceAppHelper.collect_cache_files_in_xcappdata(original_data_path) + + args = ["clear-app-data", app.bundle_identifier, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["upload-xcappdata", app.bundle_identifier, xcappdata, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["download-xcappdata", app.bundle_identifier, uploaded_data_path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + uploaded_caches = DeviceAppHelper.collect_cache_files_in_xcappdata(uploaded_data_path) + expect(uploaded_caches - original_caches).to be_empty + end + + it "works when first argument is an application path" do + args = ["clear-app-data", app.path, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + end + + it "works when first argument is a bundle identifier" do + args = ["clear-app-data", app.bundle_identifier, udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + end + end + end + end + end end end end - + context "simulators" do let (:device) { IDM::Resources.instance.default_simulator } let (:udid) { device.udid } diff --git a/spec/device_app_life_cycle_spec.rb b/spec/device_app_life_cycle_spec.rb index 399d2d31..1198dee0 100644 --- a/spec/device_app_life_cycle_spec.rb +++ b/spec/device_app_life_cycle_spec.rb @@ -1,131 +1,163 @@ -if IDM::Resources.instance.physical_device_attached? - describe "app life cycle (physical device)" do - module DeviceAppLCHelper - def self.is_installed?(udid, bundle_id) - args = ["is-installed", bundle_id, "--device-id", udid] - hash = IDM.shell(args) - - if hash[:exit_status] == IDM.exit_status(:success) || - hash[:exit_status] == IDM.exit_status(:false) - hash[:out].split($-0).last == "true" - else - raise "Expected is-installed to pass: #{hash[:out]}" - end - end - - def self.uninstall(udid, bundle_id) - if self.is_installed?(udid, bundle_id) - args = ["uninstall", bundle_id, "--device-id", udid] - hash = IDM.shell(args) - if hash[:exit_status] != IDM.exit_status(:success) - raise "Expected uninstall to pass: #{hash[:out]}" - end - end - end - end - - let(:device) { IDM::Resources.instance.default_physical_device } - let(:udid) { device.udid } - let(:app) do - path = IDM::Resources.instance.test_app(:arm) - RunLoop::App.new(path) +module DeviceAppLCHelper + def self.is_installed?(udid, bundle_id) + args = ["is-installed", bundle_id, "--device-id", udid] + hash = IDM.shell(args) + + if hash[:exit_status] == IDM.exit_status(:success) || + hash[:exit_status] == IDM.exit_status(:false) + hash[:out].split($-0).last == "true" + else + raise "Expected is-installed to pass: #{hash[:out]}" end + end - context "install apps on physical devices" do - let(:app_dupe) do - path = IDM::Resources.instance.second_test_app(:arm) - RunLoop::App.new(path) - end - - before do - DeviceAppLCHelper.uninstall(udid, app.bundle_identifier) - DeviceAppLCHelper.uninstall(udid, app_dupe.bundle_identifier) - end - - it "installs app on device indicated by --device-id" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier)).to be_truthy - end - - it "updates app if CFBundleVersion is different" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["install", app_dupe.path, "--device-id", udid] - expect(app.bundle_version).not_to be == app_dupe.bundle_version - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - expect(DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier)).to be_truthy - end - - it "updates app if CFBundleShortVersionString is different" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["install", app_dupe.path, "--device-id", udid] - expect(app.marketing_version).not_to be == app_dupe.marketing_version - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - expect(DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier)).to be_truthy - end - - it "updates app if both CFBundle versions are different" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["install", app_dupe.path, "--device-id", udid] - expect(app.bundle_version).not_to be == app_dupe.bundle_version - expect(app.marketing_version).not_to be == app_dupe.marketing_version - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - expect(DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier)).to be_truthy - end - - it "updates app if --force flag is passed" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - hash = IDM.shell(args << "--force") - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier)).to be_truthy - expect(hash[:out].include?("Installed")).to be_truthy - end - - it "does not update if app is the same" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(hash[:out].include?("not reinstalling")).to be_truthy + def self.uninstall(udid, bundle_id) + if self.is_installed?(udid, bundle_id) + args = ["uninstall", bundle_id, "--device-id", udid] + hash = IDM.shell(args) + if hash[:exit_status] != IDM.exit_status(:success) + raise "Expected uninstall to pass: #{hash[:out]}" end end + end +end - context "uninstall apps on physical devices" do - it "uninstalls app when first arg is a bundle id" do - args = ["install", app.path, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier)).to be_truthy - - args = ["uninstall", app.bundle_identifier, "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier)).to be_falsey +describe "app life cycle (physical device)" do + IDM::Resources.instance.xcode_install_paths.each do |developer_dir| + IDM::Resources.instance.with_developer_dir(developer_dir) do + # Add a simulator to this list of of devices + devices = IDM::Resources.instance.physical_devices + xcode_version = developer_dir[/(\d+\.\d+(\.\d+)?)/] + if devices.empty? + it "Xcode #{xcode_version} no compatible devices connected via USB" do + expect(true).to be == true + end + else + + context "#{developer_dir}" do + # For every connected (compatible) device + devices.each do |device| + device_str = %Q['#{device.name} (#{device.version.to_s})'] + # Run these tests + let(:udid) { device.udid } + let(:app) do + path = IDM::Resources.instance.test_app(:arm) + RunLoop::App.new(path) + end + + context "install app on #{device_str}" do + let(:app_dupe) do + path = IDM::Resources.instance.second_test_app(:arm) + RunLoop::App.new(path) + end + + before do + DeviceAppLCHelper.uninstall(udid, app.bundle_identifier) + DeviceAppLCHelper.uninstall(udid, app_dupe.bundle_identifier) + end + + it "installs app on device indicated by --device-id" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + expect( + DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier) + ).to be_truthy + end + + it "updates app if CFBundleVersion is different" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["install", app_dupe.path, "--device-id", udid] + expect(app.bundle_version).not_to be == app_dupe.bundle_version + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + expect( + DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier) + ).to be_truthy + end + + it "updates app if CFBundleShortVersionString is different" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["install", app_dupe.path, "--device-id", udid] + expect(app.marketing_version).not_to be == app_dupe.marketing_version + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + expect( + DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier) + ).to be_truthy + end + + it "updates app if both CFBundle versions are different" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["install", app_dupe.path, "--device-id", udid] + expect(app.bundle_version).not_to be == app_dupe.bundle_version + expect(app.marketing_version).not_to be == app_dupe.marketing_version + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + expect( + DeviceAppLCHelper.is_installed?(udid, app_dupe.bundle_identifier) + ).to be_truthy + end + + it "updates app if --force flag is passed" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + hash = IDM.shell(args << "--force") + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + expect( + DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier) + ).to be_truthy + expect(hash[:out].include?("Installed")).to be_truthy + end + + it "does not update if app is the same" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + expect(hash[:out].include?("not reinstalling")).to be_truthy + end + end + + context "uninstall apps on #{device_str}" do + it "uninstalls app when first arg is a bundle id" do + args = ["install", app.path, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + expect( + DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier) + ).to be_truthy + + args = ["uninstall", app.bundle_identifier, "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + expect( + DeviceAppLCHelper.is_installed?(udid, app.bundle_identifier) + ).to be_falsey + end + + it "uninstalls app when first arg is a .app bundle" + end + end + end end - - it "uninstalls app when first arg is a .app bundle" end end end diff --git a/spec/is_installed_spec.rb b/spec/is_installed_spec.rb index e932c680..b04a2ce6 100644 --- a/spec/is_installed_spec.rb +++ b/spec/is_installed_spec.rb @@ -26,30 +26,46 @@ end context "physical devices" do - let(:device) { IDM::Resources.instance.default_physical_device} - let(:udid) { device.udid } + IDM::Resources.instance.xcode_install_paths.each do |developer_dir| + IDM::Resources.instance.with_developer_dir(developer_dir) do + # Add a simulator to this list of of devices + devices = IDM::Resources.instance.physical_devices + xcode_version = developer_dir[/(\d+\.\d+(\.\d+)?)/] + if devices.empty? + it "Xcode #{xcode_version} no compatible devices connected via USB" do + expect(true).to be_truthy + end + else + context "#{developer_dir}" do + let(:app) { RunLoop::App.new(IDM::Resources.instance.test_app(:arm)) } + # For every connected (compatible) device + devices.each do |device| + context "#{device.name} (#{device.version.to_s})" do + # Run these tests + let(:udid) { device.udid } - it "prints true if app is installed" do - if device && device != "" - args = ["is-installed", "com.apple.Preferences", "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:out].split($-0).last).to be == "true" - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - else - pending("No physical device is connected") - fail - end - end + it "prints true if app is installed" do + if device && device != "" + args = ["is-installed", "com.apple.Preferences", "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:out].split($-0).last).to be == "true" + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + else + pending("No physical device is connected") + fail + end + end - it "prints false if app is not installed" do - if device && device != "" - args = ["is-installed", "com.apple.NoSuchApp", "--device-id", udid] - hash = IDM.shell(args) - expect(hash[:out].split($-0).last).to be == "false" - expect(hash[:exit_status]).to be == IDM.exit_status(:false) - else - pending("No physical device is connected") - fail + it "prints false if app is not installed" do + args = ["is-installed", "com.apple.NoSuchApp", "--device-id", udid] + hash = IDM.shell(args) + expect(hash[:out].split($-0).last).to be == "false" + expect(hash[:exit_status]).to be == IDM.exit_status(:false) + end + end + end + end + end end end end diff --git a/spec/resources.rb b/spec/resources.rb index dd7ead39..a41e634f 100644 --- a/spec/resources.rb +++ b/spec/resources.rb @@ -77,6 +77,12 @@ def default_simulator end end + def default_simulator_for_active_xcode + RunLoop::Simctl.new.simulators.detect do |sim| + sim.instruments_identifier(xcode) == RunLoop::Core.default_simulator + end + end + def random_iphone simctl.simulators.select do |sim| sim.name[/iPhone/] && @@ -91,7 +97,7 @@ def instruments def physical_devices instruments.physical_devices.select do |device| - device_compatible_with_xcode?(device, xcode) + device.compatible_with_xcode_version?(instruments.xcode.version) end end @@ -99,42 +105,6 @@ def physical_device_connected? !physical_devices.empty? end - def physical_device - return nil if !physical_device_connected? - return physical_devices[0] if physical_devices.count == 1 - - value = ENV["DEVICE_TARGET"] - if value.nil? || value == "" - raise(ArgumentError, %Q[ -More than one physical device is connected. - -Use DEVICE_TARGET={udid | device-name} or disconnect all but one device. -]) - end - - device = instruments.physical_devices.select do |elm| - elm.udid == value || elm.name == value - end - - return device if device - - raise(ArgumentError %Q[ -More than one physical device is connected. - -DEVICE_TARGET=#{value} but no matching device is connected. - -# Compatible connected devices -#{physical_devices} - -If a device is connected, it is possible that its iOS version is not -compatible with the current Xcode version. - -# Connected devices -#{instruments.physical_devices} - -]) - end - def test_app(type) @test_app_hash ||= Hash.new return @test_app_hash[type] if @test_app_hash[type] @@ -185,21 +155,6 @@ def second_test_app(type) target end - def device_compatible_with_xcode?(device, xcode) - device_version = device.version - xcode_version = xcode.version - - if device_version.major < (xcode_version.major + 2) - return true - end - - if device_version.major == (xcode_version.major + 2) - return device_version.minor <= xcode_version.minor - end - - false - end - def with_developer_dir(developer_dir, &block) original_developer_dir = ENV['DEVELOPER_DIR'] begin @@ -234,44 +189,20 @@ def with_xcode_installations(&block) end end - def physical_devices_for_testing - instruments = RunLoop::Instruments.new - xcode = instruments.xcode + def xcappdata + appdata = File.join(tmp_dir("xcappdata"), "New.xcappdata") + args = ["generate-xcappdata", appdata] + hash = IDM.shell(args) - instruments.physical_devices.select do |device| - device_compatible_with_xcode?(device, xcode) - end - end + if hash[:exit_status] != 0 + raise %Q[ +Expected generate-xcappdata to exit with 0 found: #{hash[:exit_status]} - def default_physical_device - if @default_physical_device == "" - return nil - elsif @default_physical_device - return @default_physical_device - end +#{hash[:out]} - devices = instruments.physical_devices.select do |device| - device_compatible_with_xcode?(device, xcode) +] end - if devices.empty? - @default_physical_device = "" - else - @default_physical_device = devices.first - end - end - - def physical_device_attached? - default_physical_device != "" && default_physical_device != nil - end - - def xcappdata - appdata = File.join(tmp_dir("xcappdata"), "New.xcappdata") - - args = ["generate-xcappdata", appdata] - hash = IDM.shell(args) - hash[:out] - documents = File.join(appdata, "AppData", "Documents") FileUtils.mkdir_p(documents) diff --git a/spec/resources_spec.rb b/spec/resources_spec.rb deleted file mode 100644 index 6fb8407a..00000000 --- a/spec/resources_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ - -describe "resources" do - - context "#device_compatible_with_xcode?" do - - let(:device) { IDM::Resources.instance.default_simulator } - let(:xcode) { IDM::Resources.instance.xcode } - - it "returns true if major versions are compatible" do - values = [RunLoop::Version.new("9.0"), - RunLoop::Version.new("8.0"), - RunLoop::Version.new("7.0")] - expect(device).to receive(:version).and_return(*values) - expect(xcode).to receive(:version).exactly(3).times.and_return(RunLoop::Version.new("7.0")) - - 3.times { - expect( - IDM::Resources.instance.device_compatible_with_xcode?(device, xcode) - ).to be_truthy - } - end - - it "returns true if major and minor versions are compatible" do - values = [RunLoop::Version.new("9.0"), - RunLoop::Version.new("9.1"), - RunLoop::Version.new("9.2")] - expect(device).to receive(:version).and_return(*values) - expect(xcode).to receive(:version).exactly(3).times.and_return(RunLoop::Version.new("7.2")) - - 3.times { - expect( - IDM::Resources.instance.device_compatible_with_xcode?(device, xcode) - ).to be_truthy - } - end - - it "returns false if minor versions are not compatible" do - values = [RunLoop::Version.new("9.1"), - RunLoop::Version.new("9.2"), - RunLoop::Version.new("9.3")] - expect(device).to receive(:version).and_return(*values) - expect(xcode).to receive(:version).exactly(3).times.and_return(RunLoop::Version.new("7.0")) - - 3.times { - expect( - IDM::Resources.instance.device_compatible_with_xcode?(device, xcode) - ).to be_falsey - } - end - - it "returns false if major versions are not compatible" do - values = [RunLoop::Version.new("9.0"), - RunLoop::Version.new("10.0"), - RunLoop::Version.new("11.0")] - expect(device).to receive(:version).and_return(*values) - expect(xcode).to receive(:version).exactly(3).times.and_return(RunLoop::Version.new("6.0")) - - 3.times { - expect( - IDM::Resources.instance.device_compatible_with_xcode?(device, xcode) - ).to be_falsey - } - end - end -end diff --git a/spec/upload-xcappdata_spec.rb b/spec/upload-xcappdata_spec.rb index 771f52fe..253dda01 100644 --- a/spec/upload-xcappdata_spec.rb +++ b/spec/upload-xcappdata_spec.rb @@ -1,39 +1,56 @@ -if IDM::Resources.instance.physical_device_connected? - describe "upload-xcappdata" do - - let(:device) { IDM::Resources.instance.physical_device } - let(:app) { IDM::Resources.instance.test_app(:arm) } - let(:xcappdata) do - appdata = File.join(IDM::Resources.instance.tmp_dir("xcappdata"), - "New.xcappdata") - - args = ["generate-xcappdata", appdata] - hash = IDM.shell(args) - hash[:out] - - documents = File.join(appdata, "AppData", "Documents") - FileUtils.mkdir_p(documents) - - path = File.join(documents, - "#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}.txt") - File.open(path, "w") do |file| - file.puts("content") +describe "upload-xcappdata" do + IDM::Resources.instance.xcode_install_paths.each do |developer_dir| + IDM::Resources.instance.with_developer_dir(developer_dir) do + # Add a simulator to this list of of devices + devices = IDM::Resources.instance.physical_devices + xcode_version = developer_dir[/(\d+\.\d+(\.\d+)?)/] + if devices.empty? + it "Xcode #{xcode_version} no compatible devices connected via USB" do + expect(true).to be_truthy + end + else + context "#{developer_dir}" do + let(:app) { IDM::Resources.instance.test_app(:arm) } + # For every connected (compatible) device + devices.each do |device| + context "#{device.name} (#{device.version.to_s})" do + # Run these tests + let(:xcappdata) do + appdata = File.join(IDM::Resources.instance.tmp_dir("xcappdata"), + "New.xcappdata") + + args = ["generate-xcappdata", appdata, "--overwrite", "1"] + hash = IDM.shell(args) + hash[:out] + + documents = File.join(appdata, "AppData", "Documents") + #FileUtils.mkdir_p(documents) + + path = File.join(documents, + "#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}.txt") + File.open(path, "w") do |file| + file.puts("content") + end + + hash[:out] + end + + it "uploads xcappdata" do + args = ["install", app, "--device-id", device.udid] + hash = IDM.shell(args) + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + + args = ["upload-xcappdata", app, xcappdata, + "--device-id", device.udid] + hash = IDM.shell(args) + + expect(hash[:exit_status]).to be == IDM.exit_status(:success) + end + end + end + end end - - hash[:out] - end - - it "uploads xcappdata" do - args = ["install", app, "--device-id", device.udid] - hash = IDM.shell(args) - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - - args = ["upload-xcappdata", app, xcappdata, "--device-id", device.udid] - hash = IDM.shell(args) - - expect(hash[:exit_status]).to be == IDM.exit_status(:success) - expect(hash[:out]).to be == "" end end end