2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
describe "Class#allocate" do
|
|
|
|
it "returns an instance of self" do
|
|
|
|
klass = Class.new
|
|
|
|
klass.allocate.should be_an_instance_of(klass)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a fully-formed instance of Module" do
|
|
|
|
klass = Class.allocate
|
|
|
|
klass.constants.should_not == nil
|
|
|
|
klass.methods.should_not == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "throws an exception when calling a method on a new instance" do
|
|
|
|
klass = Class.allocate
|
2019-07-27 12:40:09 +02:00
|
|
|
-> do
|
2017-05-07 12:04:49 +00:00
|
|
|
klass.new
|
|
|
|
end.should raise_error(Exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call initialize on the new instance" do
|
|
|
|
klass = Class.new do
|
|
|
|
def initialize(*args)
|
|
|
|
@initialized = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialized?
|
|
|
|
@initialized || false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-03 12:28:29 +02:00
|
|
|
klass.allocate.should_not.initialized?
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises TypeError for #superclass" do
|
2019-07-27 12:40:09 +02:00
|
|
|
-> do
|
2017-05-07 12:04:49 +00:00
|
|
|
Class.allocate.superclass
|
|
|
|
end.should raise_error(TypeError)
|
|
|
|
end
|
|
|
|
end
|