Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ios8? to device and environment helpers #561

Merged
merged 6 commits into from
Oct 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions calabash-cucumber/lib/calabash-cucumber/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def ios_major_version
version_hash(ios_version)[:major_version]
end

# Is this device running iOS 8?
# @return [Boolean] true if the major version of the OS is 8
def ios8?
ios_major_version.eql?('8')
end

# Is this device running iOS 7?
# @return [Boolean] true if the major version of the OS is 7
def ios7?
Expand Down
12 changes: 12 additions & 0 deletions calabash-cucumber/lib/calabash-cucumber/environment_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def ios7?
_OS_ENV.eql?(_canonical_os_version(:ios7)) || _default_device_or_create().ios7?
end

# Is the device under test running iOS 8?
#
# @note
# **WARNING:** The `OS` env variable has been deprecated and should
# never be set.
#
# @raise [RuntimeError] if the server cannot be reached
# @return [Boolean] true if device under test is running iOS 8
def ios8?
_default_device_or_create.ios8?
end

# Is the app that is being tested an iPhone app emulated on an iPad?
#
# @see Calabash::Cucumber::IPad
Expand Down
20 changes: 20 additions & 0 deletions calabash-cucumber/spec/device_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe Calabash::Cucumber::Device do

# noinspection RubyStringKeysInHashInspection
let(:simulator_data) { Resources.shared.server_version :simulator }
let(:endpoint) { 'http://localhost:37265' }

describe '#ios8?' do
it 'returns false when target is not iOS 8' do
device = Calabash::Cucumber::Device.new(endpoint, simulator_data)
expect(device.ios8?).to be == false
end

it 'returns true when target is iOS 8' do
simulator_data['iOS_version'] = '8.0'
device = Calabash::Cucumber::Device.new(endpoint, simulator_data)
expect(device.ios8?).to be == true
end
end

end
32 changes: 32 additions & 0 deletions calabash-cucumber/spec/environment_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Calabash
module RspecTests
module EnvironmentHelpers
class TestObject
include Calabash::Cucumber::EnvironmentHelpers
end
end
end
end

describe Calabash::Cucumber::EnvironmentHelpers do

let(:simulator_data) { Resources.shared.server_version :simulator }
let(:endpoint) { 'http://localhost:37265' }
let(:test_obj) { Calabash::RspecTests::EnvironmentHelpers::TestObject.new }

describe 'ios8?' do
it 'returns true when device under test is iOS 8' do
simulator_data['iOS_version'] = '8.0'
device = Calabash::Cucumber::Device.new(endpoint, simulator_data)
expect(test_obj).to receive(:default_device).and_return(device)
expect(test_obj.ios8?).to be == true
end

it 'returns false when device under test is not iOS 8' do
simulator_data['iOS_version'] = '7.0'
device = Calabash::Cucumber::Device.new(endpoint, simulator_data)
expect(test_obj).to receive(:default_device).and_return(device)
expect(test_obj.ios8?).to be == false
end
end
end
40 changes: 40 additions & 0 deletions calabash-cucumber/spec/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def device_for_mocking
'branch' => 'master',
'revision' => 'e494e30'
},
'screen_dimensions' => {
'scale' => 2,
'width' => 640,
'sample' => 1,
'height' => 1136
},
'app_version' => '1.4.0',
'iOS_version' => '8.0',
'system' => 'x86_64',
Expand All @@ -67,6 +73,40 @@ def device_for_mocking
Calabash::Cucumber::Device.new(endpoint, version_data)
end

def server_version(device_or_simulator)
case device_or_simulator
when :device
{}
when :simulator
{
'app_version' => '1.0',
'outcome' => 'SUCCESS',
'app_id' => 'com.xamarin.chou-cal',
'simulator_device' => 'iPhone',
'version' => '0.11.0',
'app_name' => 'chou-cal',
'iphone_app_emulated_on_ipad' => false,
'4inch' => true,
'git' => {
'remote_origin' => 'git@github.com:calabash/calabash-ios-server.git',
'branch' => 'develop',
'revision' => '652b20b'
},
'screen_dimensions' => {
'scale' => 2,
'width' => 640,
'sample' => 1,
'height' => 1136
},
'iOS_version' => '7.1',
'system' => 'x86_64',
'simulator' => 'CoreSimulator 110.2 - Device: iPhone 5 - Runtime: iOS 7.1 (11D167) - DeviceType: iPhone 5'
}
else
raise "expected '#{device_or_simulator}' to be one of #{[:simulator, :device]}"
end
end

def alt_xcode_install_paths
@alt_xcode_install_paths ||= lambda {
min_xcode_version = RunLoop::Version.new('5.1')
Expand Down