simctl 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd28b66b86819a39b9b4c3255d8a43da5a396aa4
4
- data.tar.gz: 6701555feb0245c7829b3d19164cf6104aca4091
3
+ metadata.gz: dd8b47a97cfc1f00603d9a4a34f24b8660803cc2
4
+ data.tar.gz: 40bb8ad6343667c9f5fe2f871d3c42ff299b467f
5
5
  SHA512:
6
- metadata.gz: c97dd6ebdc1afef17375c02f98aab4c139767607295a1423ae725e0c461e815020002afe7c5cbfc9f7219457db71acf8d684920451b6f4d04a51b915eea335a6
7
- data.tar.gz: 92c109f84dbcae8beb6af57a1561d56f2c239458d80d42581ae906b13e2aaa497c9e37e04c34b1c76376c8ea0981e5851eab3bd5d0743fc3f8a50951730a7f25
6
+ metadata.gz: 034237cf350ae1f5b691683cfaa113f4c0dcb8ab45f0c8e2b6fb3c5f3b3db0354d1e598374865be0f4d2d3d491597bc63e4e6434114b4614fea8010942cce857
7
+ data.tar.gz: b8b1f15f50397012431b030134d5b1d0699c9a0ad4bc19f01f93cbfd75039a4ccfde0dea66703bb3816b8b870ac2a022ba9b529255239f1a89c6ea5df9ffb5a5
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simctl (1.1.0)
4
+ simctl (1.2.0)
5
+ CFPropertyList
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ CFPropertyList (2.3.2)
9
11
  coveralls (0.8.10)
10
12
  json (~> 1.8)
11
13
  rest-client (>= 1.6.8, < 2)
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module SimCtl
2
4
  class Command
3
5
  module Create
@@ -6,11 +8,13 @@ module SimCtl
6
8
  # Creates a device
7
9
  #
8
10
  # @param name [String] name of the new device
9
- # @param device_type [SimCtl::DeviceType] device type of the new device
11
+ # @param devicetype [SimCtl::DeviceType] device type of the new device
10
12
  # @param runtime [SimCtl::Runtime] runtime of the new device
11
13
  # @return [SimCtl::Device] the device that was created
12
- def create_device(name, device_type, runtime)
13
- Executor.execute([COMMAND, "'#{name}'", device_type.identifier, runtime.identifier]) do |identifier|
14
+ def create_device(name, devicetype, runtime)
15
+ runtime = runtime(name: runtime) unless runtime.is_a?(Runtime)
16
+ devicetype = devicetype(name: devicetype) unless devicetype.is_a?(DeviceType)
17
+ Executor.execute([COMMAND, Shellwords.shellescape(name), devicetype.identifier, runtime.identifier]) do |identifier|
14
18
  device(udid: identifier)
15
19
  end
16
20
  end
@@ -2,16 +2,18 @@ module SimCtl
2
2
  class Command
3
3
  module Launch
4
4
  XCODE_HOME = `xcode-select -p`.chomp
5
+ SUPPORTED_SCALE = [1.0, 0.75, 0.5, 0.25]
5
6
 
6
7
  # Launches a Simulator instance with the given device
7
8
  #
8
9
  # @param device [SimCtl::Device] the device to launch
9
10
  # @return [void]
10
- def launch_device(device)
11
+ def launch_device(device, scale=1.0)
12
+ raise "unsupported scale '#{scale}' (supported: #{SUPPORTED_SCALE.join(', ')})" unless SUPPORTED_SCALE.include?(scale)
11
13
  # Launching the same device twice does not work.
12
14
  # Simulator.app would just hang. Solution: Kill first.
13
15
  kill_device(device)
14
- command = "open -n #{XCODE_HOME}/Applications/Simulator.app --args -ConnectHardwareKeyboard 0 -CurrentDeviceUDID #{device.udid}"
16
+ command = "open -n #{XCODE_HOME}/Applications/Simulator.app --args -ConnectHardwareKeyboard 0 -CurrentDeviceUDID #{device.udid} -SimulatorWindowLastScale-#{device.devicetype.identifier} #{scale}"
15
17
  system command
16
18
  end
17
19
  end
@@ -0,0 +1,18 @@
1
+ require 'shellwords'
2
+
3
+ module SimCtl
4
+ class Command
5
+ module Rename
6
+ COMMAND = %w[xcrun simctl rename]
7
+
8
+ # Boots a device
9
+ #
10
+ # @param device [SimCtl::Device] the device to boot
11
+ # @param name [String] the new device name
12
+ # @return [void]
13
+ def rename_device(device, name)
14
+ Executor.execute([COMMAND, device.udid, Shellwords.shellescape(name)])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,7 @@ require 'simctl/command/erase'
5
5
  require 'simctl/command/kill'
6
6
  require 'simctl/command/launch'
7
7
  require 'simctl/command/list'
8
+ require 'simctl/command/rename'
8
9
  require 'simctl/command/reset'
9
10
  require 'simctl/command/shutdown'
10
11
  require 'simctl/executor'
@@ -18,6 +19,7 @@ module SimCtl
18
19
  include SimCtl::Command::Kill
19
20
  include SimCtl::Command::Launch
20
21
  include SimCtl::Command::List
22
+ include SimCtl::Command::Rename
21
23
  include SimCtl::Command::Reset
22
24
  include SimCtl::Command::Shutdown
23
25
  end
data/lib/simctl/device.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'cfpropertylist'
2
+ require 'ostruct'
1
3
  require 'simctl/object'
2
4
  require 'timeout'
3
5
 
@@ -13,6 +15,10 @@ module SimCtl
13
15
  SimCtl.delete_device(self)
14
16
  end
15
17
 
18
+ def devicetype
19
+ @devicetype ||= SimCtl.devicetype(identifier: plist.deviceType)
20
+ end
21
+
16
22
  def erase!
17
23
  SimCtl.erase_device(self)
18
24
  end
@@ -21,8 +27,16 @@ module SimCtl
21
27
  SimCtl.kill_device(self)
22
28
  end
23
29
 
24
- def launch!
25
- SimCtl.launch_device(self)
30
+ def launch!(scale=1.0)
31
+ SimCtl.launch_device(self, scale)
32
+ end
33
+
34
+ def rename!(name)
35
+ SimCtl.rename_device(self, name)
36
+ end
37
+
38
+ def runtime
39
+ @runtime ||= SimCtl.runtime(identifier: plist.runtime)
26
40
  end
27
41
 
28
42
  def shutdown!
@@ -40,5 +54,16 @@ module SimCtl
40
54
  end
41
55
  end
42
56
  end
57
+
58
+ def ==(other)
59
+ other.udid == udid
60
+ end
61
+
62
+ private
63
+
64
+ def plist
65
+ @plist ||= OpenStruct.new(CFPropertyList.native_types(CFPropertyList::List.new(file: File.join(ENV['HOME'], 'Library/Developer/CoreSimulator/Devices', udid, 'device.plist')).value))
66
+ end
67
+
43
68
  end
44
69
  end
@@ -3,5 +3,9 @@ require 'simctl/object'
3
3
  module SimCtl
4
4
  class DeviceType < Object
5
5
  attr_reader :identifier, :name
6
+
7
+ def ==(other)
8
+ other.identifier == identifier
9
+ end
6
10
  end
7
11
  end
@@ -3,5 +3,9 @@ require 'simctl/object'
3
3
  module SimCtl
4
4
  class Runtime < Object
5
5
  attr_reader :availability, :buildversion, :identifier, :name, :version
6
+
7
+ def ==(other)
8
+ other.identifier == identifier
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module SimCtl
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/simctl.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'maxitest'
23
23
  s.add_development_dependency 'shoulda-context'
24
24
  s.add_development_dependency 'coveralls'
25
+
26
+ s.add_dependency 'CFPropertyList'
25
27
  end
@@ -6,7 +6,7 @@ class SimCtl::Command::CRUDTest < Minitest::Test
6
6
  @devicetype = SimCtl.list_devicetypes.select {|devicetype| devicetype.name =~ %r[iPhone]}.first
7
7
  @runtime = SimCtl.list_runtimes.select {|runtime| runtime.name =~ %r[iOS.*9]}.first
8
8
  @device = SimCtl.create_device SecureRandom.hex, @devicetype, @runtime
9
- @device.wait! {|device| device.state != :creating}
9
+ @device.wait! {|d| d.state != :creating}
10
10
  end
11
11
 
12
12
  def teardown
@@ -14,6 +14,20 @@ class SimCtl::Command::CRUDTest < Minitest::Test
14
14
  return unless device
15
15
  device.kill!
16
16
  device.shutdown! if device.state != :shutdown
17
+ device.wait! {|d| d.state == :shutdown}
18
+ device.delete!
19
+ end
20
+
21
+ should 'have devicetype and runtime property' do
22
+ device = SimCtl.device(udid: @device.udid)
23
+ assert device == @device
24
+ assert device.devicetype == @devicetype
25
+ assert device.runtime == @runtime
26
+ end
27
+
28
+ should 'lookup devicetype and runtime strings' do
29
+ device = SimCtl.create_device SecureRandom.hex, @devicetype.name, @runtime.name
30
+ device.wait! {|d| d.state != :creating}
17
31
  device.delete!
18
32
  end
19
33
 
@@ -30,21 +44,22 @@ class SimCtl::Command::CRUDTest < Minitest::Test
30
44
  should 'launch and kill the device created in setup' do
31
45
  device = SimCtl.device(udid: @device.udid)
32
46
  assert device.launch!
33
- device.wait!{|device| device.state == :booted}
47
+ device.wait!{|d| d.state == :booted}
34
48
  assert device.kill!
49
+ device.wait!{|d| d.state == :shutdown}
35
50
  end
36
51
 
37
52
  should 'erase the device created in setup' do
38
53
  device = SimCtl.device(udid: @device.udid)
39
- SimCtl.erase_device device
54
+ device.erase!
40
55
  end
41
56
 
42
57
  should 'boot/shutdown the device created in setup' do
43
58
  device = SimCtl.device(udid: @device.udid)
44
- SimCtl.boot_device device
45
- device.wait! {|device| device.state == :booted}
46
- SimCtl.shutdown_device device
47
- device.wait! {|device| device.state == :shutdown}
59
+ device.boot!
60
+ device.wait! {|d| d.state == :booted}
61
+ device.shutdown!
62
+ device.wait! {|d| d.state == :shutdown}
48
63
  end
49
64
 
50
65
  should 'delete the device created in setup' do
@@ -53,11 +68,17 @@ class SimCtl::Command::CRUDTest < Minitest::Test
53
68
  assert_nil SimCtl.device(udid: @device.udid)
54
69
  end
55
70
 
71
+ should 'rename the device created in setup' do
72
+ device = SimCtl.device(udid: @device.udid)
73
+ device.rename!('new name')
74
+ assert SimCtl.device(udid: @device.udid).name == 'new name'
75
+ end
76
+
56
77
  should 'reset the device created in setup' do
57
78
  device = SimCtl.reset_device @device.name, @devicetype, @runtime
58
79
  assert_kind_of SimCtl::Device, device
59
80
  assert_nil SimCtl.device(udid: @device.udid)
60
81
  @device = device # teardown cleanup
61
- device.wait! {|device| device.state != :creating}
82
+ device.wait! {|d| d.state != :creating}
62
83
  end
63
84
  end
@@ -57,4 +57,10 @@ class SimCtl::Command::ListTest < Minitest::Test
57
57
  end
58
58
  end
59
59
 
60
+ context 'unknown method' do
61
+ should 'raise an exception' do
62
+ assert_raises { SimCtl.foo }
63
+ end
64
+ end
65
+
60
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Plunien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: CFPropertyList
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Ruby interface to xcrun simctl
70
84
  email:
71
85
  - plu@pqpq.de
@@ -90,6 +104,7 @@ files:
90
104
  - lib/simctl/command/kill.rb
91
105
  - lib/simctl/command/launch.rb
92
106
  - lib/simctl/command/list.rb
107
+ - lib/simctl/command/rename.rb
93
108
  - lib/simctl/command/reset.rb
94
109
  - lib/simctl/command/shutdown.rb
95
110
  - lib/simctl/device.rb