Skip to content

Commit

Permalink
Merge pull request #211 from calabash/feature/configure-tests-to-targ…
Browse files Browse the repository at this point in the history
…et-connected-devices

Spec: run tests against connected physical devices
  • Loading branch information
jmoody committed May 8, 2018
2 parents 0b3837e + 4d2137a commit 1e34858
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 418 deletions.
196 changes: 105 additions & 91 deletions spec/clear_app_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 1e34858

Please sign in to comment.