Restructure and expand test coverage

This commit is contained in:
David Larrabee
2015-01-13 22:52:14 -05:00
parent 99fd52443e
commit a4afb7e914
14 changed files with 410 additions and 457 deletions

15
spec/ext/object_spec.rb Normal file
View File

@@ -0,0 +1,15 @@
describe 'Object' do
before { @subject = Object.new }
it "should return the RMQ App when Object#app is called" do
@subject.app.should.equal(RubyMotionQuery::App)
end
it "should return the RMQ Device when Object#device is called" do
@subject.device.should.equal(RubyMotionQuery::Device)
end
it "find should be an alias for rmq" do
@subject.find.is_a?(RubyMotionQuery::RMQ).should.be.true
end
end

View File

@@ -1,4 +1,4 @@
describe 'Redpotion ext' do
describe 'UIColor' do
it "should allow you to get a new color from an existing color with 'with'" do
trans_black = UIColor.blackColor.with(alpha: 0.5)
trans_black.should.equal(UIColor.colorWithRed(0, green: 0, blue: 0, alpha: 0.5))

View File

@@ -1,47 +1,144 @@
describe 'UIViewController' do
module DelegateTestAttributes
attr_accessor :view_did_load_count
attr_accessor :view_will_appear_count
attr_accessor :view_did_appear_count
def view_did_load
self.view_did_load_count ||= 0
self.view_did_load_count += 1
end
def view_will_appear(animated)
self.view_will_appear_count ||= 0
self.view_will_appear_count += 1
end
def view_did_appear(animated)
self.view_did_appear_count ||= 0
self.view_did_appear_count += 1
end
end
class TestController < UIViewController; include DelegateTestAttributes; end
class TestScreen < PM::Screen; include DelegateTestAttributes; end
shared 'proper delegate caller' do
it 'should call view_will_appear only once' do
controller.view_will_appear_count.should.equal(1)
end
it 'should call view_did_load only once' do
controller.view_did_load_count.should.equal(1)
end
it 'should call view_did_appear only once' do
# we need to check the view to make it 'appear'
views(UIView).should.not.be.nil
controller.view_did_appear_count.should.equal(1)
end
it 'should call view_did_load only once' do
controller.view_did_load_count.should.equal(1)
end
end
describe 'when using a PM::Screen' do
tests TestScreen
behaves_like 'proper delegate caller'
describe 'append' do
it "should return a RMQ object" do
appended = controller.append(UIView, nil, {})
appended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
appended = controller.append(UIView, nil, {})
appended.get.is_a?(UIView).should.be.true
end
end
describe "append!" do
it "should return the appended object" do
appended = controller.append!(UIView, nil, {})
appended.is_a?(UIView).should.be.true
end
end
describe "prepend" do
it "should return a RMQ object" do
prepended = controller.prepend(UIView, nil, {})
prepended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
prepended = controller.prepend(UIView, nil, {})
prepended.get.is_a?(UIView).should.be.true
end
end
describe "prepend!" do
it "should return the appended object" do
prepended = controller.prepend!(UIView, nil, {})
prepended.is_a?(UIView).should.be.true
end
end
describe "create" do
it "should return a RMQ object" do
created = controller.create(UIView, nil, {})
created.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
created = controller.create(UIView, nil, {})
created.get.is_a?(UIView).should.be.true
end
end
describe "create!" do
it "should return the appended object" do
created = controller.create!(UIView, nil, {})
created.is_a?(UIView).should.be.true
end
end
describe "build" do
it "should return a RMQ object" do
built = controller.build(UIView, nil, {})
built.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
built = controller.build(UIView, nil, {})
built.get.is_a?(UIView).should.be.true
end
end
describe "build!" do
it "should return the appended object" do
built = controller.build!(UIView, nil, {})
built.is_a?(UIView).should.be.true
end
end
describe "color" do
it "should return rmq.color" do
controller.color.should.equal(RubyMotionQuery::Color)
end
end
describe "font" do
it "should return rmq.font" do
controller.font.should.equal(RubyMotionQuery::Font)
end
end
describe "image" do
it "should return rmq.image" do
controller.image.should.equal(RubyMotionQuery::ImageUtils)
end
end
describe "stylesheet" do
it "should return rmq.stylesheet" do
controller.stylesheet.should.equal(controller.rmq.stylesheet)
end
end
describe "stylesheet=" do
it "should set rmq.stylesheet" do
controller.stylesheet = TestScreenStylesheet
controller.rmq.stylesheet.is_a?(TestScreenStylesheet).should.be.true
end
end
describe "reapply_styles" do
it "should reapply styles" do
@view = controller.append!(UILabel, :test_label)
@view.text.should.equal('style from sheet')
@view.text = nil
@view.text.should.be.nil
controller.reapply_styles
@view.text.should.equal('style from sheet')
end
end
end
describe 'when using a controller' do

220
spec/ext/ui_view_spec.rb Normal file
View File

@@ -0,0 +1,220 @@
describe 'UIView' do
it "should call on_load instead of rmq_build if rmq_build does not exist in the view" do
rmq.create(TestView).get.on_loaded.should == true
test_view = TestView.alloc.initWithFrame([[0,0],[10,10]])
test_view.on_loaded.should.be.nil
rmq.build(test_view)
test_view.on_loaded.should.be.true
end
it "should call on_styled instead of rmq_style_applied if rmq_style_applied does not exist in the view" do
test_view = rmq.create!(TestView, :root_view)
test_view.on_styled_fired.should.be.true
test_view = TestView.alloc.initWithFrame([[0,0],[10,10]])
test_view.on_styled_fired.should.be.nil
test_view.apply_style(:root_view)
test_view.on_styled_fired.should.be.true
end
describe "#append" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
appended = @view.append(UIView, nil, {})
appended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
appended = @view.append(UIView, nil, {})
appended.get.is_a?(UIView).should.be.true
end
end
describe "append!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
appended = @view.append!(UIView, nil, {})
appended.is_a?(UIView).should.be.true
end
end
describe "prepend" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
prepended = @view.prepend(UIView, nil, {})
prepended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
prepended = @view.prepend(UIView, nil, {})
prepended.get.is_a?(UIView).should.be.true
end
end
describe "prepend!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
prepended = @view.prepend!(UIView, nil, {})
prepended.is_a?(UIView).should.be.true
end
end
describe "create" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
created = @view.create(UIView, nil, {})
created.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
created = @view.create(UIView, nil, {})
created.get.is_a?(UIView).should.be.true
end
end
describe "create!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
created = @view.create!(UIView, nil, {})
created.is_a?(UIView).should.be.true
end
end
describe "build" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
built = @view.build(UIView, nil, {})
built.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
built = @view.build(UIView, nil, {})
built.get.is_a?(UIView).should.be.true
end
end
describe "build!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
built = @view.build!(UIView, nil, {})
built.is_a?(UIView).should.be.true
end
end
describe "on" do
before do
@button = UIButton.alloc.init
@button.on(:tap, {}) { }
end
it "should attach the event" do
@button.rmq_data.events.has_event?(:tap).should.be.true
end
end
describe "off" do
before do
@button = UIButton.alloc.init
@button.on(:tap, {}) { }
@button.on(:swipe, {}) { }
@button.on(:value_changed, {}) { }
end
describe "removing a single event when many exist" do
before do
@button.off(:tap)
end
it "should detach the events" do
@button.rmq_data.events.has_event?(:tap).should.be.false
@button.rmq_data.events.has_event?(:swipe).should.be.true
@button.rmq_data.events.has_event?(:value_changed).should.be.true
end
end
describe "removing multiple events when many exist" do
before do
@button.off(:swipe, :value_changed)
end
it "should detach the events" do
@button.rmq_data.events.has_event?(:tap).should.be.true
@button.rmq_data.events.has_event?(:swipe).should.be.false
@button.rmq_data.events.has_event?(:value_changed).should.be.false
end
end
end
describe "apply_style" do
before do
@view = UILabel.alloc.init
@view.rmq.stylesheet = TestScreenStylesheet
@view.apply_style(:test_label)
end
it "should style the view" do
@view.text.should.equal("style from sheet")
end
end
describe "style" do
before do
@view = UILabel.alloc.init
@view.style do |st|
st.text = "test style"
end
end
it "should have styled the view" do
@view.text.should.equal("test style")
end
end
describe "color" do
before { @view = UIView.alloc.init }
it "should return rmq.color" do
@view.color.should.equal(RubyMotionQuery::Color)
end
end
describe "font" do
before { @view = UIView.alloc.init }
it "should return rmq.font" do
@view.font.should.equal(RubyMotionQuery::Font)
end
end
describe "image" do
before { @view = UIView.alloc.init }
it "should return rmq.image" do
@view.image.should.equal(RubyMotionQuery::ImageUtils)
end
end
describe "stylesheet" do
before { @view = UIView.alloc.init }
it "should return rmq.stylesheet" do
@view.stylesheet.should.equal(@view.rmq.stylesheet)
end
end
describe "stylesheet=" do
before { @view = UIView.alloc.init }
it "should set rmq.stylesheet" do
@view.stylesheet = TestScreenStylesheet
@view.rmq.stylesheet.is_a?(TestScreenStylesheet).should.be.true
end
end
end

View File

@@ -1,4 +1,3 @@
module Bacon
class Context
include CDQ

View File

@@ -18,7 +18,7 @@ describe 'ScreenModule' do
describe "not providing a stylesheet" do
class TestScreenTwo < PM::Screen; end
it "should raise exception if the stylesheet is not defined in the class" do
it "should not raise exception if the stylesheet is not defined in the class" do
should.not.raise(RuntimeError) do
TestScreenTwo.new.view_did_load
end

View File

@@ -1,419 +0,0 @@
describe 'RubyMotionQuery ext' do
it "should return the RMQ App when Object#app is called" do
object = Object.new
object.app.should.equal(RubyMotionQuery::App)
end
it "should return the RMQ Device when Object#device is called" do
object = Object.new
object.device.should.equal(RubyMotionQuery::Device)
end
it "find should be an alias for rmq" do
object = Object.new
object.find.is_a?(RubyMotionQuery::RMQ).should.be.true
end
describe "UIView" do
it "should call on_load instead of rmq_build if rmq_build does not exist in the view" do
rmq.create(TestView).get.on_loaded.should == true
test_view = TestView.alloc.initWithFrame([[0,0],[10,10]])
test_view.on_loaded.should.be.nil
rmq.build(test_view)
test_view.on_loaded.should.be.true
end
it "should call on_styled instead of rmq_style_applied if rmq_style_applied does not exist in the view" do
test_view = rmq.create!(TestView, :root_view)
test_view.on_styled_fired.should.be.true
test_view = TestView.alloc.initWithFrame([[0,0],[10,10]])
test_view.on_styled_fired.should.be.nil
test_view.apply_style(:root_view)
test_view.on_styled_fired.should.be.true
end
describe "#append" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
appended = @view.append(UIView, nil, {})
appended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
appended = @view.append(UIView, nil, {})
appended.get.is_a?(UIView).should.be.true
end
end
describe "append!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
appended = @view.append!(UIView, nil, {})
appended.is_a?(UIView).should.be.true
end
end
describe "prepend" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
prepended = @view.prepend(UIView, nil, {})
prepended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
prepended = @view.prepend(UIView, nil, {})
prepended.get.is_a?(UIView).should.be.true
end
end
describe "prepend!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
prepended = @view.prepend!(UIView, nil, {})
prepended.is_a?(UIView).should.be.true
end
end
describe "create" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
created = @view.create(UIView, nil, {})
created.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
created = @view.create(UIView, nil, {})
created.get.is_a?(UIView).should.be.true
end
end
describe "create!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
created = @view.create!(UIView, nil, {})
created.is_a?(UIView).should.be.true
end
end
describe "build" do
before { @view = UIView.alloc.init }
it "should return a RMQ object" do
built = @view.build(UIView, nil, {})
built.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
built = @view.build(UIView, nil, {})
built.get.is_a?(UIView).should.be.true
end
end
describe "build!" do
before { @view = UIView.alloc.init }
it "should return the appended object" do
built = @view.build!(UIView, nil, {})
built.is_a?(UIView).should.be.true
end
end
describe "on" do
before do
@button = UIButton.alloc.init
@button.on(:tap, {}) { }
end
it "should attach the event" do
@button.rmq_data.events.has_event?(:tap).should.be.true
end
end
describe "off" do
before do
@button = UIButton.alloc.init
@button.on(:tap, {}) { }
@button.on(:swipe, {}) { }
@button.on(:value_changed, {}) { }
end
describe "removing a single event when many exist" do
before do
@button.off(:tap)
end
it "should detach the events" do
@button.rmq_data.events.has_event?(:tap).should.be.false
@button.rmq_data.events.has_event?(:swipe).should.be.true
@button.rmq_data.events.has_event?(:value_changed).should.be.true
end
end
describe "removing multiple events when many exist" do
before do
@button.off(:swipe, :value_changed)
end
it "should detach the events" do
@button.rmq_data.events.has_event?(:tap).should.be.true
@button.rmq_data.events.has_event?(:swipe).should.be.false
@button.rmq_data.events.has_event?(:value_changed).should.be.false
end
end
end
describe "apply_style" do
class TestStylesheet
def fake(st)
st.text = 'style from sheet'
end
end
before do
@view = UILabel.alloc.init
@view.rmq.stylesheet = TestStylesheet
@view.apply_style(:fake)
end
it "should style the view" do
@view.text.should.equal("style from sheet")
end
end
describe "reapply_styles" do
class TestStylesheet
def fake(st)
st.text = 'style from sheet'
end
end
it "should reapply styles" do
@view = rmq.append!(UILabel, :fake)
@view.text.should.equal('style from sheet')
@view.text = nil
@view.text.should.be.nil
@view.reapply_styles
@view.text.should.equal('style from sheet')
end
end
describe "style" do
before do
@view = UILabel.alloc.init
@view.style do |st|
st.text = "test style"
end
end
it "should have styled the view" do
@view.text.should.equal("test style")
end
end
describe "color" do
before { @view = UIView.alloc.init }
it "should return rmq.color" do
@view.color.should.equal(RubyMotionQuery::Color)
end
end
describe "font" do
before { @view = UIView.alloc.init }
it "should return rmq.font" do
@view.font.should.equal(RubyMotionQuery::Font)
end
end
describe "image" do
before { @view = UIView.alloc.init }
it "should return rmq.image" do
@view.image.should.equal(RubyMotionQuery::ImageUtils)
end
end
describe "stylesheet" do
before { @view = UIView.alloc.init }
it "should return rmq.stylesheet" do
@view.stylesheet.should.equal(@view.rmq.stylesheet)
end
end
describe "stylesheet=" do
before { @view = UIView.alloc.init }
class FakeStylesheetForTest;end
it "should set rmq.stylesheet" do
@view.stylesheet = FakeStylesheetForTest
@view.rmq.stylesheet.is_a?(FakeStylesheetForTest).should.be.true
end
end
end
describe "Promotion::Screen" do
class TestScreenStylesheet < ApplicationStylesheet
def root_view(st)
st.background_color = color.white
end
end
class TestScreen < PM::Screen
stylesheet TestScreenStylesheet
end
before { @screen = TestScreen.new }
describe "append" do
it "should return a RMQ object" do
appended = @screen.append(UIView, nil, {})
appended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
appended = @screen.append(UIView, nil, {})
appended.get.is_a?(UIView).should.be.true
end
end
describe "append!" do
it "should return the appended object" do
appended = @screen.append!(UIView, nil, {})
appended.is_a?(UIView).should.be.true
end
end
describe "prepend" do
it "should return a RMQ object" do
prepended = @screen.prepend(UIView, nil, {})
prepended.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
prepended = @screen.prepend(UIView, nil, {})
prepended.get.is_a?(UIView).should.be.true
end
end
describe "prepend!" do
it "should return the appended object" do
prepended = @screen.prepend!(UIView, nil, {})
prepended.is_a?(UIView).should.be.true
end
end
describe "create" do
it "should return a RMQ object" do
created = @screen.create(UIView, nil, {})
created.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
created = @screen.create(UIView, nil, {})
created.get.is_a?(UIView).should.be.true
end
end
describe "create!" do
it "should return the appended object" do
created = @screen.create!(UIView, nil, {})
created.is_a?(UIView).should.be.true
end
end
describe "build" do
it "should return a RMQ object" do
built = @screen.build(UIView, nil, {})
built.is_a?(RubyMotionQuery::RMQ).should.be.true
end
it "should create a new object class provided" do
built = @screen.build(UIView, nil, {})
built.get.is_a?(UIView).should.be.true
end
end
describe "build!" do
it "should return the appended object" do
built = @screen.build!(UIView, nil, {})
built.is_a?(UIView).should.be.true
end
end
describe "reapply_styles" do
class TestStylesheet
def root_view(st)
st.background_color = UIColor.greenColor
end
def fake(st)
st.text = 'style from sheet'
end
end
it "should reapply styles" do
TestScreen.stylesheet(TestStylesheet)
@view = @screen.append!(UILabel, :fake)
@view.text.should.equal('style from sheet')
@view.text = nil
@view.text.should.be.nil
@screen.reapply_styles
@view.text.should.equal('style from sheet')
end
end
describe "color" do
it "should return rmq.color" do
@screen.color.should.equal(RubyMotionQuery::Color)
end
end
describe "font" do
it "should return rmq.font" do
@screen.font.should.equal(RubyMotionQuery::Font)
end
end
describe "image" do
it "should return rmq.image" do
@screen.image.should.equal(RubyMotionQuery::ImageUtils)
end
end
describe "stylesheet" do
it "should return rmq.stylesheet" do
@screen.stylesheet.should.equal(@screen.rmq.stylesheet)
end
end
describe "stylesheet=" do
class FakeStylesheetForTest;end
it "should set rmq.stylesheet" do
@screen.stylesheet = FakeStylesheetForTest
@screen.rmq.stylesheet.is_a?(FakeStylesheetForTest).should.be.true
end
end
end
end
class TestView < UIView
attr_reader :on_loaded
attr_reader :on_styled_fired
def on_load
@on_loaded = true
end
def on_styled
@on_styled_fired = true
end
end

View File

@@ -1,8 +0,0 @@
describe 'MetalTableScreen' do
before do
end
after do
end
end