From 4a211219822d4932e925cef11517b7649dd382ba Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 25 Sep 2014 14:26:02 -0500 Subject: [PATCH 1/2] added tests :sparkles: --- motion/ruby_motion_query/device.rb | 13 +++++++++++++ spec/device.rb | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/motion/ruby_motion_query/device.rb b/motion/ruby_motion_query/device.rb index cb657a6..bcd50eb 100644 --- a/motion/ruby_motion_query/device.rb +++ b/motion/ruby_motion_query/device.rb @@ -17,6 +17,19 @@ module RubyMotionQuery @_ios_eight ||= screen.respond_to?(:coordinateSpace) end + # Find out what version of iOS you're using. + # `rmq.device.is_version? 8` + # `rmq.device.is_version? "7.1"` + # + # @return [Boolean] + def is_version? version + !!ios_version.match("^#{version}") + end + + def ios_version + UIDevice.currentDevice.systemVersion + end + # @return [UIScreen] def screen UIScreen.mainScreen diff --git a/spec/device.rb b/spec/device.rb index 66b5b58..1a89ad0 100644 --- a/spec/device.rb +++ b/spec/device.rb @@ -31,6 +31,21 @@ describe 'device' do rmq.device.should == RubyMotionQuery::Device end + it 'can detect what iOS version is in use' do + rmq.device.ios_version.should == UIDevice.currentDevice.systemVersion + #validate this is numbers and dots + rmq.device.ios_version.match(/^(\d|\.)+$/).should.not == nil + end + + it 'can let you know if it is a version of iOS' do + current_version = rmq.device.ios_version + rmq.device.is_version?(current_version).should == true + # fail condition + rmq.device.is_version?(2).should == false + # can check with just major version number like 7 for "7.1" + rmq.device.is_version?(current_version[0]).should == true + end + it 'should have a screen' do @rmq.device.screen.should == UIScreen.mainScreen end From aab48a18d1594ab7309b7136d5cbdb3851697703 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 25 Sep 2014 14:31:14 -0500 Subject: [PATCH 2/2] small verbiage change --- spec/device.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/device.rb b/spec/device.rb index 1a89ad0..8f08505 100644 --- a/spec/device.rb +++ b/spec/device.rb @@ -37,7 +37,7 @@ describe 'device' do rmq.device.ios_version.match(/^(\d|\.)+$/).should.not == nil end - it 'can let you know if it is a version of iOS' do + it 'lets you know if a queried version of iOS is correct' do current_version = rmq.device.ios_version rmq.device.is_version?(current_version).should == true # fail condition