[macruby-changes] [794] MacRuby/trunk/test/hotcocoa
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jan 20 06:41:34 PST 2009
Revision: 794
http://trac.macosforge.org/projects/ruby/changeset/794
Author: eloy.de.enige at gmail.com
Date: 2009-01-20 06:41:34 -0800 (Tue, 20 Jan 2009)
Log Message:
-----------
Tests for HotCocoa::Mapper and HotCocoa::Mappings
Added Paths:
-----------
MacRuby/trunk/test/hotcocoa/test_mapper.rb
MacRuby/trunk/test/hotcocoa/test_mappings.rb
Added: MacRuby/trunk/test/hotcocoa/test_mapper.rb
===================================================================
--- MacRuby/trunk/test/hotcocoa/test_mapper.rb (rev 0)
+++ MacRuby/trunk/test/hotcocoa/test_mapper.rb 2009-01-20 14:41:34 UTC (rev 794)
@@ -0,0 +1,63 @@
+require 'hotcocoa'
+require File.join(File.dirname(__FILE__), '..', 'test_helper')
+
+class SampleClass
+end
+
+class TestMapper < Test::Unit::TestCase
+
+ include HotCocoa::Mappings
+
+ it "should have two hash attributes named #bindings and #delegate" do
+ assert Mapper.bindings_modules.is_a?(Hash)
+ assert Mapper.delegate_modules.is_a?(Hash)
+ end
+
+ [ :control_class, :builder_method, :control_module,
+ :map_bindings, :map_bindings= ].each do |method|
+
+ it "should have a #{method} attribute" do
+ assert_respond_to(sample_mapper, method)
+ end
+
+ end
+
+ it "should set it's control class on initialization" do
+ assert_equal(sample_mapper(true).control_class, SampleClass)
+ end
+
+ it "should convert from camelcase to underscore" do
+ assert sample_mapper.underscore("SampleCamelCasedWord"), 'sample_camel_cased_word'
+ end
+
+ def test_include_in_class
+
+ m = sample_mapper(true)
+ m.include_in_class
+
+ assert_equal m.instance_variable_get('@extension_method'), :include
+
+ flunk 'Pending.'
+
+ end
+
+ def test_each_control_ancestor
+ flunk 'Pending.'
+ end
+
+ def test_map_class
+ flunk 'Pending.'
+ end
+
+ def test_map_instances_of
+ flunk 'Pending.'
+ end
+
+ private
+
+ def sample_mapper(flush = false)
+ @mapper = nil if flush
+ @mapper || Mapper.new(SampleClass)
+ end
+
+end
Added: MacRuby/trunk/test/hotcocoa/test_mappings.rb
===================================================================
--- MacRuby/trunk/test/hotcocoa/test_mappings.rb (rev 0)
+++ MacRuby/trunk/test/hotcocoa/test_mappings.rb 2009-01-20 14:41:34 UTC (rev 794)
@@ -0,0 +1,82 @@
+require 'hotcocoa'
+require File.join(File.dirname(__FILE__), '..', 'test_helper')
+
+class SampleClass
+ def self.val; @val || false; end
+ def self.val= (v); @val = v; end
+end
+
+class TestMappings < Test::Unit::TestCase
+
+ include HotCocoa
+
+ it "should have two Hash attributes named #mappings and #frameworks" do
+ assert Mappings.mappings.is_a?(Hash)
+ assert Mappings.frameworks.is_a?(Hash)
+ end
+
+ it "should register callbacks for the point of time when a framework is loaded with #on_framework" do
+ p = Proc.new {}
+ Mappings.on_framework(:Foo, &p)
+ assert_equal(Mappings.frameworks['foo'].last, p)
+ end
+
+ it "should create a mapping to a class with #map" do
+
+ block = Proc.new do
+ def alloc_with_options(options); options; end
+ end
+
+ HotCocoa::Mappings.map({:foo => :SampleClass}, &block)
+
+ m = HotCocoa::Mappings.mappings[:foo]
+
+ assert_equal(m.control_class, SampleClass)
+ assert_equal(m.builder_method, :foo)
+ assert(m.control_module.instance_methods.include?(:alloc_with_options))
+
+ end
+
+ it "should create a mapping to a class for a framework with #map" do
+
+ p = Proc.new {}
+
+ HotCocoa::Mappings.map({:foo => :SampleClass, :framework => :Anonymous}, &p)
+
+ require 'pp'; pp HotCocoa::Mappings
+
+ # FIXME: This is not really nice. We test that the result exists, but not what it is.
+ assert_equal Mappings.frameworks["anonymous"].size, 1
+
+ end
+
+ it "should call the framework's callbacks if it's passed to #framework_loaded" do
+
+ p = Proc.new { SampleClass.val = true }
+
+ Mappings.on_framework(:Foo, &p)
+ Mappings.framework_loaded(:Foo)
+
+ assert_equal SampleClass.val, true
+
+ end
+
+ it "should raise nothing if there's no entry for the framework passed to #framework_loaded" do
+
+ assert_nothing_raised do
+ Mappings.framework_loaded(:FrameworkDoesNotExist)
+ end
+
+ end
+
+ def test_reload
+ flunk 'Pending.'
+ end
+
+ private
+
+ # Helper methods for test_framework_loaded
+ def self.foo_loaded; @foo_loaded; end
+ def self.foo_loaded=(val); @foo_loaded = val; end
+
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090120/23c44091/attachment.html>
More information about the macruby-changes
mailing list