mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-23 12:27:56 +08:00
added weakref spec
This commit is contained in:
35
test/test/spec/weakref_spec.rb
Normal file
35
test/test/spec/weakref_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
describe "WeakRef" do
|
||||
it "creates proxy objects that forward messages" do
|
||||
ary = [1, 2, 3]
|
||||
ref = WeakRef.new(ary)
|
||||
ref.class.should == Array
|
||||
ref[0].should == 1
|
||||
ref[1].should == 2
|
||||
ref[2].should == 3
|
||||
ref.should == ary
|
||||
end
|
||||
|
||||
it "creates proxy objects that forward respond_to?" do
|
||||
ary = [1, 2, 3]
|
||||
ref = WeakRef.new(ary)
|
||||
ary.methods.each { |x| ref.respond_to?(x).should == true }
|
||||
end
|
||||
|
||||
it "creates weak references" do
|
||||
obj = Object.new
|
||||
rc = obj.retainCount
|
||||
ref = WeakRef.new(obj)
|
||||
obj.retainCount.should == rc
|
||||
end
|
||||
|
||||
it "passes the internal reference when given to ObjC APIs" do
|
||||
ary = [1, 2, 3]
|
||||
ref = WeakRef.new(ary)
|
||||
ary2 = NSArray.arrayWithArray(ref)
|
||||
ary2.should == ary
|
||||
end
|
||||
|
||||
it "cannot be subclassed" do
|
||||
lambda { class Foo < WeakRef; end }.should.raise(RuntimeError)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user