diff --git a/motion/ruby_motion_query/device.rb b/motion/ruby_motion_query/device.rb index 0b2d510..69bc52f 100644 --- a/motion/ruby_motion_query/device.rb +++ b/motion/ruby_motion_query/device.rb @@ -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 diff --git a/spec/device.rb b/spec/device.rb index 0cc56b1..a544b4e 100644 --- a/spec/device.rb +++ b/spec/device.rb @@ -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