Module: Spec::Example::ModuleReopeningFix

Included in:
ExampleMethods
Defined in:
lib/vendor/plugins/rspec/lib/spec/example/module_reopening_fix.rb

Overview

When you reopen a module that is included in another module that is included in a class, the new material you define does not make it to the class. This fixes that.

Example

module M1; end

module M2
  def foo; "FOO"; end
end

class C
  include M1
end

module M1
  include M2
end

c = C.new
c.foo
NoMethodError: undefined method `foo' for #<C:0x5e89a4>
  from (irb):12

Instance Method Summary collapse

Instance Method Details

#child_modulesObject



27
28
29
# File 'lib/vendor/plugins/rspec/lib/spec/example/module_reopening_fix.rb', line 27

def child_modules
  @child_modules ||= []
end

#include(mod) ⇒ Object



35
36
37
38
39
40
# File 'lib/vendor/plugins/rspec/lib/spec/example/module_reopening_fix.rb', line 35

def include(mod)
  super
  child_modules.each do |child_module|
    child_module.__send__(:include, mod)
  end
end

#included(mod) ⇒ Object



31
32
33
# File 'lib/vendor/plugins/rspec/lib/spec/example/module_reopening_fix.rb', line 31

def included(mod)
  child_modules << mod
end