Class: Calabash::Cucumber::Device
- Inherits:
-
Object
- Object
- Calabash::Cucumber::Device
- Defined in:
- lib/calabash-cucumber/device.rb
Overview
Class device encapsulates information about the device or devices we are interacting with during a test. Credit: Due to jmoody’s briar: github.com/jmoody/briar/blob/master/lib/briar/gestalt.rb
Constant Summary collapse
- GESTALT_IPHONE =
'iPhone'
- GESTALT_IPAD =
'iPad'
- GESTALT_IPHONE5 =
'Retina 4-inch'
- GESTALT_SIM_SYS =
'x86_64'
- GESTALT_IPOD =
'iPod'
Instance Attribute Summary collapse
-
#device_family ⇒ Object
readonly
Returns the value of attribute device_family.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#framework_version ⇒ Object
readonly
Returns the value of attribute framework_version.
-
#ios_version ⇒ Object
readonly
Returns the value of attribute ios_version.
-
#simulator_details ⇒ Object
readonly
Returns the value of attribute simulator_details.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
-
#udid ⇒ Object
Returns the value of attribute udid.
Instance Method Summary collapse
- #device? ⇒ Boolean
-
#initialize(endpoint, version_data) ⇒ Device
constructor
A new instance of Device.
- #ios5? ⇒ Boolean
- #ios6? ⇒ Boolean
- #ios_major_version ⇒ Object
- #ipad? ⇒ Boolean
- #iphone? ⇒ Boolean
- #iphone_5? ⇒ Boolean
- #ipod? ⇒ Boolean
- #simulator? ⇒ Boolean
- #version_hash(version_str) ⇒ Object
Constructor Details
#initialize(endpoint, version_data) ⇒ Device
Returns a new instance of Device.
26 27 28 29 30 31 32 33 34 |
# File 'lib/calabash-cucumber/device.rb', line 26 def initialize (endpoint, version_data) simulator_device = version_data['simulator_device'] @endpoint = endpoint @system = version_data['system'] @device_family = @system.eql?(GESTALT_SIM_SYS) ? simulator_device : @system.split(/[\d,.]/).first @simulator_details = version_data['simulator'] @ios_version = version_data['iOS_version'] @framework_version = version_data['version'] end |
Instance Attribute Details
#device_family ⇒ Object (readonly)
Returns the value of attribute device_family.
19 20 21 |
# File 'lib/calabash-cucumber/device.rb', line 19 def device_family @device_family end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
18 19 20 |
# File 'lib/calabash-cucumber/device.rb', line 18 def endpoint @endpoint end |
#framework_version ⇒ Object (readonly)
Returns the value of attribute framework_version.
22 23 24 |
# File 'lib/calabash-cucumber/device.rb', line 22 def framework_version @framework_version end |
#ios_version ⇒ Object (readonly)
Returns the value of attribute ios_version.
20 21 22 |
# File 'lib/calabash-cucumber/device.rb', line 20 def ios_version @ios_version end |
#simulator_details ⇒ Object (readonly)
Returns the value of attribute simulator_details.
20 21 22 |
# File 'lib/calabash-cucumber/device.rb', line 20 def simulator_details @simulator_details end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
21 22 23 |
# File 'lib/calabash-cucumber/device.rb', line 21 def system @system end |
#udid ⇒ Object
Returns the value of attribute udid.
24 25 26 |
# File 'lib/calabash-cucumber/device.rb', line 24 def udid @udid end |
Instance Method Details
#device? ⇒ Boolean
40 41 42 |
# File 'lib/calabash-cucumber/device.rb', line 40 def device? not simulator? end |
#ios5? ⇒ Boolean
79 80 81 |
# File 'lib/calabash-cucumber/device.rb', line 79 def ios5? ios_major_version.eql?('5') end |
#ios6? ⇒ Boolean
75 76 77 |
# File 'lib/calabash-cucumber/device.rb', line 75 def ios6? ios_major_version.eql?('6') end |
#ios_major_version ⇒ Object
71 72 73 |
# File 'lib/calabash-cucumber/device.rb', line 71 def ios_major_version version_hash(ios_version)[:major_version] end |
#ipad? ⇒ Boolean
52 53 54 |
# File 'lib/calabash-cucumber/device.rb', line 52 def ipad? device_family.eql? GESTALT_IPAD end |
#iphone? ⇒ Boolean
44 45 46 |
# File 'lib/calabash-cucumber/device.rb', line 44 def iphone? device_family.eql? GESTALT_IPHONE end |
#iphone_5? ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/calabash-cucumber/device.rb', line 56 def iphone_5? if simulator? simulator_details.split(/[(),]/)[3].eql? GESTALT_IPHONE5 else system.split(/[\D]/).delete_if { |x| x.eql?('') }.first.eql?('5') end end |
#ipod? ⇒ Boolean
48 49 50 |
# File 'lib/calabash-cucumber/device.rb', line 48 def ipod? device_family.eql? GESTALT_IPOD end |
#simulator? ⇒ Boolean
36 37 38 |
# File 'lib/calabash-cucumber/device.rb', line 36 def simulator? system.eql?(GESTALT_SIM_SYS) end |
#version_hash(version_str) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/calabash-cucumber/device.rb', line 64 def version_hash (version_str) tokens = version_str.split(/[,.]/) {:major_version => tokens[0], :minor_version => tokens[1], :bug_version => tokens[2]} end |