Created
May 22, 2009 23:00
-
-
Save jredville/116409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../../spec_helper' | |
describe "ObjectSpace.each_object" do | |
it "calls the block once for each living, nonimmediate object in the Ruby process" do | |
class ObjectSpaceSpecEachObject; end | |
new_obj = ObjectSpaceSpecEachObject.new | |
count = ObjectSpace.each_object(ObjectSpaceSpecEachObject) {} | |
count.should == 1 | |
# this is needed to prevent the new_obj from being GC'd too early | |
new_obj.should_not == nil | |
end | |
deviates_on(:ironruby) do | |
it "raises NotSupportedException for non-Class classes" do | |
lambda { ObjectSpace.each_object(String) {} }.should raise_error(RuntimeError) | |
end | |
end | |
it "works for Module" do | |
modules = [] | |
ObjectSpace.each_object(Module) { |o| modules << o } | |
modules.size.should > 90 | |
modules.each { |m| m.should be_kind_of(Module) } | |
end | |
it "works for Class" do | |
classes = [] | |
ObjectSpace.each_object(Class) { |o| classes << o } | |
classes.size.should > 70 | |
classes.each { |c| c.should be_kind_of(Class) } | |
end | |
it "works for singleton Class" do | |
moduleClass = class << Module; self; end | |
classClass = class << Class; self; end | |
ObjectSpace.each_object(moduleClass) {}.should >= 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment