Skip to content

@jredville /object_space_spec.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.