Added rmq.device.three_point_five_inch?, rmq.device.four_point_seven_inch?, and rmq.device.five_point_five_inch?

This commit is contained in:
Todd Werth
2014-09-21 22:10:19 -07:00
parent a1e362deb0
commit ca83b4cc12
2 changed files with 63 additions and 14 deletions

View File

@@ -51,11 +51,26 @@ module RubyMotionQuery
@_simulator
end
def three_point_five_inch?
@_three_point_five_inch = (Device.height == 480.0) if @_three_point_five_inch.nil?
@_three_point_five_inch
end
def four_inch?
@_four_inch = (Device.height == 568.0) if @_four_inch.nil?
@_four_inch
end
def four_point_seven_inch?
@_four_point_seven_inch = (Device.height == 667.0) if @_four_point_seven_inch.nil?
@_four_point_seven_inch
end
def five_point_five_inch?
@_five_point_five_inch = (Device.height == 736.0) if @_five_point_five_inch.nil?
@_five_point_five_inch
end
def retina?
if @_retina.nil?
main_screen = Device.screen

View File

@@ -1,3 +1,23 @@
class RubyMotionQuery::Device
class << self
def fake_height(value)
@_three_point_five_inch = nil
@_four_inch = nil
@_four_point_seven_inch = nil
@_five_point_five_inch = nil
@_height = value
end
def reset_fake_caches
@_three_point_five_inch = nil
@_four_inch = nil
@_four_point_seven_inch = nil
@_five_point_five_inch = nil
@_height = nil
end
end
end
describe 'device' do
before do
@rmq = RubyMotionQuery::RMQ
@@ -55,28 +75,42 @@ describe 'device' do
@rmq.device.simulator?.should == false
end
it 'should return the right value for three_point_five_inch?' do
@rmq.device.fake_height(480)
@rmq.device.three_point_five_inch?.should == true
@rmq.device.fake_height(10)
@rmq.device.three_point_five_inch?.should == false
@rmq.device.reset_fake_caches
end
it 'should return the right value for four_inch?' do
@rmq.device.fake_height(568)
@rmq.device.four_inch?.should == true
class RubyMotionQuery::Device
class << self
def fake_height(value)
@_four_inch = nil
@_height = value
end
def reset_fake_caches
@_four_inch = nil
@_height = nil
end
end
end
@rmq.device.fake_height(10)
@rmq.device.four_inch?.should == false
@rmq.device.reset_fake_caches
end
it 'should return the right value for four_point_seven_inch?' do
@rmq.device.fake_height(667)
@rmq.device.four_point_seven_inch?.should == true
@rmq.device.fake_height(10)
@rmq.device.four_point_seven_inch?.should == false
@rmq.device.reset_fake_caches
end
it 'should return the right value for five_point_five_inch?' do
@rmq.device.fake_height(736)
@rmq.device.five_point_five_inch?.should == true
@rmq.device.fake_height(10)
@rmq.device.five_point_five_inch?.should == false
@rmq.device.reset_fake_caches
end
describe 'retina?' do
#TODO finish
end