Skip to content

Commit

Permalink
Refactor a couple Module#prepend specs
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 14, 2015
1 parent 4be5200 commit 26c4d68
Showing 2 changed files with 26 additions and 18 deletions.
6 changes: 2 additions & 4 deletions spec/ruby/core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -505,13 +505,11 @@ def self.get_constant_from_scope_with_send(method)
end
end

class SuperInClassMethodWithPrepend
class RecordIncludedModules
def self.inherited(base)
super
ScratchPad.record base
end
end

SuperInClassMethodWithPrepend.singleton_class.prepend(Module.new)
end

class Object
38 changes: 24 additions & 14 deletions spec/ruby/core/module/prepend_spec.rb
Original file line number Diff line number Diff line change
@@ -269,28 +269,38 @@ class PC
end

it "supports super when the module is prepended into a singleton class" do
module ModuleSpecs::PrependSuperInSingleton
def included(base)
ScratchPad.record []

mod = Module.new do
def self.inherited(base)
super
end
end

module ModuleSpecs::PrependSuperInSingletonModule
class << self
prepend ModuleSpecs::PrependSuperInSingleton
end
module_with_singleton_class_prepend = Module.new do
singleton_class.prepend mod
end

lambda do
class ModuleSpecs::PrependSuperInSingletonClass
include ModuleSpecs::PrependSuperInSingletonModule
end
end.should_not raise_error
klass = Class.new(ModuleSpecs::RecordIncludedModules) do
include module_with_singleton_class_prepend
end

ScratchPad.recorded.should == klass
end

it "supports super when the module is prepended into a singleton class with a class super" do
lambda do
Class.new(ModuleSpecs::SuperInClassMethodWithPrepend)
end.should_not raise_error
ScratchPad.record []

base_class = Class.new(ModuleSpecs::RecordIncludedModules) do
def self.inherited(base)
super
end
end

prepended_module = Module.new
base_class.singleton_class.prepend(prepended_module)

child_class = Class.new(base_class)
ScratchPad.recorded.should == child_class
end
end

0 comments on commit 26c4d68

Please sign in to comment.