simctl 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +80 -0
  4. data/.travis.yml +5 -4
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile.lock +20 -3
  7. data/README.md +3 -3
  8. data/fastlane-plugin-simctl/.gitignore +11 -0
  9. data/fastlane-plugin-simctl/.rspec +3 -0
  10. data/fastlane-plugin-simctl/.rubocop.yml +263 -0
  11. data/fastlane-plugin-simctl/Gemfile +6 -0
  12. data/fastlane-plugin-simctl/README.md +46 -0
  13. data/fastlane-plugin-simctl/Rakefile +9 -0
  14. data/fastlane-plugin-simctl/fastlane-plugin-simctl.gemspec +29 -0
  15. data/fastlane-plugin-simctl/fastlane/Fastfile +9 -0
  16. data/fastlane-plugin-simctl/fastlane/Pluginfile +1 -0
  17. data/fastlane-plugin-simctl/lib/fastlane/plugin/simctl.rb +16 -0
  18. data/fastlane-plugin-simctl/lib/fastlane/plugin/simctl/actions/simctl_action.rb +51 -0
  19. data/fastlane-plugin-simctl/lib/fastlane/plugin/simctl/helper/simctl_helper.rb +52 -0
  20. data/fastlane-plugin-simctl/lib/fastlane/plugin/simctl/version.rb +5 -0
  21. data/fastlane-plugin-simctl/spec/simctl_action_spec.rb +4 -0
  22. data/fastlane-plugin-simctl/spec/spec_helper.rb +15 -0
  23. data/lib/simctl.rb +1 -1
  24. data/lib/simctl/command/create.rb +3 -2
  25. data/lib/simctl/command/delete.rb +1 -1
  26. data/lib/simctl/command/erase.rb +0 -2
  27. data/lib/simctl/command/io.rb +3 -3
  28. data/lib/simctl/command/launch.rb +6 -6
  29. data/lib/simctl/command/list.rb +8 -6
  30. data/lib/simctl/command/reset.rb +2 -2
  31. data/lib/simctl/command/spawn.rb +4 -2
  32. data/lib/simctl/command/terminate.rb +4 -4
  33. data/lib/simctl/command/warmup.rb +3 -3
  34. data/lib/simctl/device.rb +14 -14
  35. data/lib/simctl/device_launchctl.rb +3 -3
  36. data/lib/simctl/device_path.rb +18 -7
  37. data/lib/simctl/device_settings.rb +5 -5
  38. data/lib/simctl/device_type.rb +1 -1
  39. data/lib/simctl/executor.rb +3 -3
  40. data/lib/simctl/list.rb +6 -6
  41. data/lib/simctl/object.rb +1 -1
  42. data/lib/simctl/runtime.rb +2 -2
  43. data/lib/simctl/version.rb +1 -1
  44. data/lib/simctl/xcode/path.rb +10 -4
  45. data/lib/simctl/xcode/version.rb +3 -3
  46. data/simctl.gemspec +3 -1
  47. data/spec/simctl/device_interaction_spec.rb +11 -11
  48. data/spec/simctl/executor_spec.rb +1 -1
  49. data/spec/simctl/list_spec.rb +6 -2
  50. data/spec/simctl/readme_spec.rb +5 -5
  51. data/spec/simctl/warmup_spec.rb +1 -1
  52. data/spec/spec_helper.rb +9 -13
  53. metadata +33 -2
@@ -7,13 +7,13 @@ module SimCtl
7
7
  # @param runtime [String] runtime string
8
8
  # @param timeout [Integer] timeout in seconds to wait until device is ready
9
9
  # @return [SimCtl::Device]
10
- def warmup(devicetype, runtime, timeout=120)
10
+ def warmup(devicetype, runtime, timeout = 120)
11
11
  devicetype = devicetype(name: devicetype) unless devicetype.is_a?(DeviceType)
12
12
  runtime = runtime(name: runtime) unless runtime.is_a?(Runtime)
13
13
  device = device(devicetype: devicetype, runtime: runtime)
14
- raise DeviceNotFound.new("Could not find device with type '#{devicetype.name}' and runtime '#{runtime.name}'") if device.nil?
14
+ raise DeviceNotFound, "Could not find device with type '#{devicetype.name}' and runtime '#{runtime.name}'" if device.nil?
15
15
  device.launch
16
- device.wait(timeout) {|d| d.state == :booted && d.ready?}
16
+ device.wait(timeout) { |d| d.state == :booted && d.ready? }
17
17
  device
18
18
  end
19
19
  end
@@ -71,7 +71,7 @@ module SimCtl
71
71
  # Launches the Simulator
72
72
  #
73
73
  # @return [void]
74
- def launch(scale=1.0, opts={})
74
+ def launch(scale = 1.0, opts = {})
75
75
  SimCtl.launch_device(self, scale, opts)
76
76
  end
77
77
 
@@ -88,7 +88,7 @@ module SimCtl
88
88
  # @param identifier [String] the app identifier
89
89
  # @param args [Array] optional launch arguments
90
90
  # @return [void]
91
- def launch_app(identifier, args=[], opts={})
91
+ def launch_app(identifier, args = [], opts = {})
92
92
  SimCtl.launch_app(self, identifier, args, opts)
93
93
  end
94
94
 
@@ -97,7 +97,7 @@ module SimCtl
97
97
  # @param identifier [String] the app identifier
98
98
  # @param args [Array] optional terminate arguments
99
99
  # @return [void]
100
- def terminate_app(identifier, args=[])
100
+ def terminate_app(identifier, args = [])
101
101
  SimCtl.terminate_app(self, identifier, args)
102
102
  end
103
103
 
@@ -121,7 +121,7 @@ module SimCtl
121
121
  #
122
122
  # @return [Bool]
123
123
  def ready?
124
- running_services = launchctl.list.reject {|service| service.pid.to_i == 0 }.map {|service| service.name}
124
+ running_services = launchctl.list.reject { |service| service.pid.to_i == 0 }.map(&:name)
125
125
  (required_services_for_ready - running_services).empty?
126
126
  end
127
127
 
@@ -164,7 +164,7 @@ module SimCtl
164
164
  # * type: Can be png, tiff, bmp, gif, jpeg (default is png)
165
165
  # * display: Can be main or tv for iOS, tv for tvOS and main for watchOS
166
166
  # @return [void]
167
- def screenshot(file, opts={})
167
+ def screenshot(file, opts = {})
168
168
  SimCtl.screenshot(self, file, opts)
169
169
  end
170
170
 
@@ -187,7 +187,7 @@ module SimCtl
187
187
  # @param path [String] path to executable
188
188
  # @param args [Array] arguments for the executable
189
189
  # @return [void]
190
- def spawn(path, args=[], opts={})
190
+ def spawn(path, args = [], opts = {})
191
191
  SimCtl.spawn(self, path, args, opts)
192
192
  end
193
193
 
@@ -201,8 +201,8 @@ module SimCtl
201
201
  # Reloads the device until the given block returns true
202
202
  #
203
203
  # @return [void]
204
- def wait(timeout=SimCtl.default_timeout)
205
- Timeout::timeout(timeout) do
204
+ def wait(timeout = SimCtl.default_timeout)
205
+ Timeout.timeout(timeout) do
206
206
  loop do
207
207
  break if yield SimCtl.device(udid: udid)
208
208
  end
@@ -212,7 +212,7 @@ module SimCtl
212
212
 
213
213
  def ==(other)
214
214
  return false if other.nil?
215
- return false unless other.kind_of? Device
215
+ return false unless other.is_a? Device
216
216
  other.udid == udid
217
217
  end
218
218
 
@@ -239,12 +239,12 @@ module SimCtl
239
239
  if Xcode::Version.gte? '8.0'
240
240
  [
241
241
  'com.apple.mobileassetd',
242
- 'com.apple.nsurlsessiond',
242
+ 'com.apple.nsurlsessiond'
243
243
  ]
244
244
  else
245
245
  [
246
246
  'com.apple.mobileassetd',
247
- 'com.apple.networkd',
247
+ 'com.apple.networkd'
248
248
  ]
249
249
  end
250
250
  when :ios
@@ -253,20 +253,20 @@ module SimCtl
253
253
  'com.apple.backboardd',
254
254
  'com.apple.mobile.installd',
255
255
  'com.apple.CoreSimulator.bridge',
256
- 'com.apple.SpringBoard',
256
+ 'com.apple.SpringBoard'
257
257
  ]
258
258
  elsif Xcode::Version.gte? '8.0'
259
259
  [
260
260
  'com.apple.SimulatorBridge',
261
261
  'com.apple.SpringBoard',
262
262
  'com.apple.backboardd',
263
- 'com.apple.mobile.installd',
263
+ 'com.apple.mobile.installd'
264
264
  ]
265
265
  else
266
266
  [
267
267
  'com.apple.SimulatorBridge',
268
268
  'com.apple.SpringBoard',
269
- 'com.apple.mobile.installd',
269
+ 'com.apple.mobile.installd'
270
270
  ]
271
271
  end
272
272
  else
@@ -7,13 +7,13 @@ module SimCtl
7
7
  end
8
8
 
9
9
  def list
10
- fields = [:pid, :status, :name]
10
+ fields = %i[pid status name]
11
11
  device
12
12
  .spawn(device.path.launchctl, ['list'])
13
13
  .split("\n")
14
14
  .drop(1)
15
- .map {|item| Hash[fields.zip(item.split("\t"))] }
16
- .map {|item| OpenStruct.new(item) }
15
+ .map { |item| Hash[fields.zip(item.split("\t"))] }
16
+ .map { |item| OpenStruct.new(item) }
17
17
  end
18
18
 
19
19
  private
@@ -1,3 +1,5 @@
1
+ require 'cfpropertylist'
2
+
1
3
  module SimCtl
2
4
  class DevicePath
3
5
  def initialize(device)
@@ -17,11 +19,7 @@ module SimCtl
17
19
  end
18
20
 
19
21
  def launchctl
20
- @launchctl ||= if Xcode::Version.gte? '9.0'
21
- "#{Xcode::Path.home}//Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl"
22
- else
23
- File.join(runtime_root, 'bin/launchctl')
24
- end
22
+ @launchctl ||= File.join(runtime_root, 'bin/launchctl')
25
23
  end
26
24
 
27
25
  def preferences_plist
@@ -38,9 +36,22 @@ module SimCtl
38
36
  end
39
37
 
40
38
  def locate_runtime_root
41
- "/Library/Developer/CoreSimulator/Profiles/Runtimes/#{device.runtime.name}.simruntime/Contents/Resources/RuntimeRoot".tap do |path|
42
- return path if File.exists?(path)
39
+ runtime_identifier = device.runtime.identifier
40
+
41
+ [
42
+ Xcode::Path.runtime_profiles,
43
+ '/Library/Developer/CoreSimulator/Profiles/Runtimes/'
44
+ ].each do |parent_dir|
45
+ Dir.glob(File.join(File.expand_path(parent_dir), '*')).each do |dir|
46
+ plist_path = File.join(dir, 'Contents/Info.plist')
47
+ next unless File.exist?(plist_path)
48
+ info = CFPropertyList.native_types(CFPropertyList::List.new(file: plist_path).value)
49
+ next unless info.is_a?(Hash) && (info['CFBundleIdentifier'] == runtime_identifier)
50
+ root_path = File.join(dir, 'Contents/Resources/RuntimeRoot')
51
+ return root_path if File.exist?(root_path)
52
+ end
43
53
  end
54
+
44
55
  Xcode::Path.sdk_root
45
56
  end
46
57
 
@@ -13,7 +13,7 @@ module SimCtl
13
13
  # @return [void]
14
14
  def disable_keyboard_helpers
15
15
  edit_plist(path.preferences_plist) do |plist|
16
- %w(
16
+ %w[
17
17
  KeyboardAllowPaddle
18
18
  KeyboardAssistant
19
19
  KeyboardAutocapitalization
@@ -23,7 +23,7 @@ module SimCtl
23
23
  KeyboardPeriodShortcut
24
24
  KeyboardPrediction
25
25
  KeyboardShowPredictionBar
26
- ).each do |key|
26
+ ].each do |key|
27
27
  plist[key] = false
28
28
  end
29
29
  end
@@ -39,8 +39,8 @@ module SimCtl
39
39
  end
40
40
  end
41
41
 
42
- def edit_plist(path, &block)
43
- plist = File.exists?(path) ? CFPropertyList::List.new(file: path) : CFPropertyList::List.new
42
+ def edit_plist(path)
43
+ plist = File.exist?(path) ? CFPropertyList::List.new(file: path) : CFPropertyList::List.new
44
44
  content = CFPropertyList.native_types(plist.value) || {}
45
45
  yield content
46
46
  plist.value = CFPropertyList.guess(content)
@@ -53,7 +53,7 @@ module SimCtl
53
53
  def set_language(language)
54
54
  edit_plist(path.global_preferences_plist) do |plist|
55
55
  key = 'AppleLanguages'
56
- plist[key] = [] unless plist.has_key?(key)
56
+ plist[key] = [] unless plist.key?(key)
57
57
  plist[key].unshift(language).uniq!
58
58
  end
59
59
  end
@@ -6,7 +6,7 @@ module SimCtl
6
6
 
7
7
  def ==(other)
8
8
  return false if other.nil?
9
- return false unless other.kind_of? DeviceType
9
+ return false unless other.is_a? DeviceType
10
10
  other.identifier == identifier
11
11
  end
12
12
  end
@@ -7,11 +7,11 @@ module SimCtl
7
7
  def execute(command)
8
8
  command = command.flatten.join(' ')
9
9
  $stderr.puts command if ENV['SIMCTL_DEBUG']
10
- Open3.popen3(command) do |stdin, stdout, stderr, result|
10
+ Open3.popen3(command) do |_stdin, stdout, stderr, result|
11
11
  output = stdout.read
12
12
  if result.value.to_i > 0
13
13
  output = stderr.read if output.empty?
14
- raise RuntimeError.new(output)
14
+ raise output
15
15
  end
16
16
  return unless block_given?
17
17
  if looks_like_json?(output)
@@ -25,7 +25,7 @@ module SimCtl
25
25
  private
26
26
 
27
27
  def looks_like_json?(output)
28
- output.start_with?('[') || output.start_with?('{')
28
+ output.start_with?('[', '{')
29
29
  end
30
30
  end
31
31
  end
@@ -12,12 +12,12 @@ module SimCtl
12
12
  select do |item|
13
13
  matches = true
14
14
  filter.each do |key, value|
15
- case value
16
- when Regexp
17
- matches &= item.send(key) =~ value
18
- else
19
- matches &= item.send(key) == value
20
- end
15
+ matches &= case value
16
+ when Regexp
17
+ item.send(key) =~ value
18
+ else
19
+ item.send(key) == value
20
+ end
21
21
  end
22
22
  matches
23
23
  end
@@ -1,7 +1,7 @@
1
1
  module SimCtl
2
2
  class Object
3
3
  def initialize(args)
4
- args.each do |k,v|
4
+ args.each do |k, v|
5
5
  instance_variable_set("@#{k}", v) unless v.nil?
6
6
  end
7
7
  end
@@ -11,7 +11,7 @@ module SimCtl
11
11
 
12
12
  def ==(other)
13
13
  return false if other.nil?
14
- return false unless other.kind_of? Runtime
14
+ return false unless other.is_a? Runtime
15
15
  other.identifier == identifier
16
16
  end
17
17
 
@@ -20,7 +20,7 @@ module SimCtl
20
20
  # @param name [String] type (ios, watchos, tvos)
21
21
  # @return [SimCtl::Runtime] the latest available runtime
22
22
  def self.latest(type)
23
- Naturally.sort_by(SimCtl.list_runtimes.where(name: %r|#{type}|i), :version).last
23
+ Naturally.sort_by(SimCtl.list_runtimes.where(name: /#{type}/i), :version).last
24
24
  end
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module SimCtl
2
- VERSION = '1.6.2'
2
+ VERSION = '1.6.3'.freeze
3
3
  end
@@ -1,15 +1,21 @@
1
1
  module SimCtl
2
2
  module Xcode
3
3
  class Path
4
- HOME=`xcode-select -p`.chomp
5
-
6
4
  class << self
7
5
  def home
8
- HOME
6
+ @home ||= `xcode-select -p`.chomp
9
7
  end
10
8
 
11
9
  def sdk_root
12
- File.join(HOME, 'Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk')
10
+ File.join(home, 'Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk')
11
+ end
12
+
13
+ def runtime_profiles
14
+ if Xcode::Version.gte? '9.0'
15
+ File.join(home, 'Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/')
16
+ else
17
+ File.join(home, 'Platforms/iPhoneSimulator.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/')
18
+ end
13
19
  end
14
20
  end
15
21
  end
@@ -1,11 +1,11 @@
1
1
  module SimCtl
2
2
  module Xcode
3
3
  class Version
4
- VERSION = Gem::Version.new(`xcodebuild -version`.scan(/Xcode (\S+)/).flatten.first)
5
-
6
4
  class << self
7
5
  def gte?(version)
8
- VERSION >= Gem::Version.new(version)
6
+ @version ||= Gem::Version.new(`xcodebuild -version`.scan(/Xcode (\S+)/).flatten.first)
7
+
8
+ @version >= Gem::Version.new(version)
9
9
  end
10
10
  end
11
11
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
4
  require 'simctl/version'
4
5
 
@@ -9,7 +10,7 @@ Gem::Specification.new do |s|
9
10
  s.description = 'Ruby interface to xcrun simctl'
10
11
 
11
12
  s.authors = ['Johannes Plunien']
12
- s.email = %w(plu@pqpq.de)
13
+ s.email = %w[plu@pqpq.de]
13
14
  s.homepage = 'https://github.com/plu/simctl'
14
15
  s.licenses = ['MIT']
15
16
 
@@ -21,6 +22,7 @@ Gem::Specification.new do |s|
21
22
  s.add_development_dependency 'coveralls'
22
23
  s.add_development_dependency 'rake'
23
24
  s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'rubocop'
24
26
 
25
27
  s.add_dependency 'CFPropertyList'
26
28
  s.add_dependency 'naturally'
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
  RSpec.describe SimCtl, order: :defined do
5
5
  before(:all) do
6
6
  @name = SecureRandom.hex
7
- @devicetype = SimCtl.devicetype(name: 'iPhone 5')
7
+ @devicetype = SimCtl.devicetype(name: 'iPhone 6')
8
8
  @runtime = SimCtl::Runtime.latest(:ios)
9
9
  @device = SimCtl.create_device @name, @devicetype, @runtime
10
- @device.wait {|d| d.state == :shutdown}
10
+ @device.wait { |d| d.state == :shutdown }
11
11
  end
12
12
 
13
13
  after(:all) do
14
14
  with_rescue { @device.kill }
15
- with_rescue { @device.wait {|d| d.state == :shutdown} }
15
+ with_rescue { @device.wait { |d| d.state == :shutdown } }
16
16
  with_rescue { @device.delete }
17
17
  end
18
18
 
@@ -77,7 +77,7 @@ RSpec.describe SimCtl, order: :defined do
77
77
  describe 'device settings' do
78
78
  describe 'update hardware keyboard' do
79
79
  it 'creates the preferences plist' do
80
- File.delete(@device.path.preferences_plist) if File.exists?(@device.path.preferences_plist)
80
+ File.delete(@device.path.preferences_plist) if File.exist?(@device.path.preferences_plist)
81
81
  @device.settings.update_hardware_keyboard(false)
82
82
  expect(File).to exist(@device.path.preferences_plist)
83
83
  end
@@ -85,7 +85,7 @@ RSpec.describe SimCtl, order: :defined do
85
85
 
86
86
  describe 'disable keyboard helpers' do
87
87
  it 'creates the preferences plist' do
88
- File.delete(@device.path.preferences_plist) if File.exists?(@device.path.preferences_plist)
88
+ File.delete(@device.path.preferences_plist) if File.exist?(@device.path.preferences_plist)
89
89
  @device.settings.disable_keyboard_helpers
90
90
  expect(File).to exist(@device.path.preferences_plist)
91
91
  end
@@ -139,12 +139,12 @@ RSpec.describe SimCtl, order: :defined do
139
139
  describe 'launching the device' do
140
140
  it 'launches the device' do
141
141
  @device.launch
142
- @device.wait {|d| d.state == :booted}
142
+ @device.wait { |d| d.state == :booted }
143
143
  expect(@device.state).to be == :booted
144
144
  end
145
145
 
146
146
  it 'is ready' do
147
- @device.wait {|d| d.ready?}
147
+ @device.wait(&:ready?)
148
148
  expect(@device).to be_ready
149
149
  end
150
150
  end
@@ -223,7 +223,7 @@ RSpec.describe SimCtl, order: :defined do
223
223
 
224
224
  it 'kills the device' do
225
225
  @device.kill
226
- @device.wait {|d| d.state == :shutdown}
226
+ @device.wait { |d| d.state == :shutdown }
227
227
  end
228
228
 
229
229
  it 'state is shutdown' do
@@ -238,7 +238,7 @@ RSpec.describe SimCtl, order: :defined do
238
238
 
239
239
  it 'boots the device' do
240
240
  @device.boot
241
- @device.wait {|d| d.state == :booted}
241
+ @device.wait { |d| d.state == :booted }
242
242
  expect(@device.state).to be == :booted
243
243
  end
244
244
 
@@ -247,7 +247,7 @@ RSpec.describe SimCtl, order: :defined do
247
247
  end
248
248
 
249
249
  it 'is ready' do
250
- @device.wait {|d| d.ready?}
250
+ @device.wait(&:ready?)
251
251
  expect(@device).to be_ready
252
252
  end
253
253
  end
@@ -259,7 +259,7 @@ RSpec.describe SimCtl, order: :defined do
259
259
 
260
260
  it 'shuts down the device' do
261
261
  @device.shutdown
262
- @device.wait {|d| d.state == :shutdown}
262
+ @device.wait { |d| d.state == :shutdown }
263
263
  end
264
264
 
265
265
  it 'state is shutdown' do