Revision: 3938 http://trac.macosforge.org/projects/ruby/changeset/3938 Author: lsansonetti@apple.com Date: 2010-04-16 17:55:39 -0700 (Fri, 16 Apr 2010) Log Message: ----------- added specs to cover automatic class +initialize upon lazy lookup Modified Paths: -------------- MacRuby/trunk/spec/macruby/core/object_spec.rb MacRuby/trunk/spec/macruby/fixtures/object.m Modified: MacRuby/trunk/spec/macruby/core/object_spec.rb =================================================================== --- MacRuby/trunk/spec/macruby/core/object_spec.rb 2010-04-16 23:59:45 UTC (rev 3937) +++ MacRuby/trunk/spec/macruby/core/object_spec.rb 2010-04-17 00:55:39 UTC (rev 3938) @@ -51,4 +51,15 @@ o2.frozen?.should == false end -end \ No newline at end of file +end + +describe "An Objective-C class" do + it "has its +initialize method called once it is accessed for the first time" do + 3.times { ::TestClassInitialization.result.should == 42 } + + # If +[NSPredicate initialize] is not properly called, this will raise a warning in the + # running terminal (see https://www.macruby.org/trac/ticket/458). + obj = NSPredicate.predicateWithFormat("NOT (SELF in %@)", argumentArray: [[1,2,3,4]]) + obj.kind_of?(NSPredicate).should == true + end +end Modified: MacRuby/trunk/spec/macruby/fixtures/object.m =================================================================== --- MacRuby/trunk/spec/macruby/fixtures/object.m 2010-04-16 23:59:45 UTC (rev 3937) +++ MacRuby/trunk/spec/macruby/fixtures/object.m 2010-04-17 00:55:39 UTC (rev 3938) @@ -22,4 +22,25 @@ @end +@interface TestClassInitialization : NSObject +@end + +@implementation TestClassInitialization + +static int res = 0; + ++ (void)initialize +{ + if (self == [TestClassInitialization class]) { + res += 42; + } +} + ++ (int)result +{ + return res; +} + +@end + void Init_object(void) {}