1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Module#append_features" do
it "is a private method" do
Module.should have_private_instance_method(:append_features)
end
describe "on Class" do
it "is undefined" do
Class.should_not have_private_instance_method(:append_features, true)
end
it "raises a TypeError if calling after rebinded to Class" do
-> {
Module.instance_method(:append_features).bind(Class.new).call Module.new
}.should raise_error(TypeError)
end
end
it "gets called when self is included in another module/class" do
begin
m = Module.new do
def self.append_features(mod)
$appended_to = mod
end
end
c = Class.new do
include m
end
$appended_to.should == c
ensure
$appended_to = nil
end
end
it "raises an ArgumentError on a cyclic include" do
-> {
ModuleSpecs::CyclicAppendA.send(:append_features, ModuleSpecs::CyclicAppendA)
}.should raise_error(ArgumentError)
-> {
ModuleSpecs::CyclicAppendB.send(:append_features, ModuleSpecs::CyclicAppendA)
}.should raise_error(ArgumentError)
end
describe "when other is frozen" do
before :each do
@receiver = Module.new
@other = Module.new.freeze
end
it "raises a FrozenError before appending self" do
-> { @receiver.send(:append_features, @other) }.should raise_error(FrozenError)
@other.ancestors.should_not include(@receiver)
end
end
end
|