forked from dkubb/adamantium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Adamantium::ModuleMethods#included
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Adamantium::ModuleMethods, '#included' do | ||
subject { descendant.instance_exec(object) { |mod| include mod } } | ||
|
||
let(:object) { Module.new.extend(described_class) } | ||
let(:descendant) { Class.new } | ||
let(:superclass) { Module } | ||
|
||
before do | ||
# Prevent Module.included from being called through inheritance | ||
Adamantium.stub(:included) | ||
end | ||
|
||
around do |example| | ||
# Restore included method after each example | ||
superclass.class_eval do | ||
alias_method :original_included, :included | ||
example.call | ||
undef_method :included | ||
alias_method :included, :original_included | ||
end | ||
end | ||
|
||
it 'delegates to the superclass #included method' do | ||
# This is the most succinct approach I could think of to test whether the | ||
# superclass#included method is called. All of the built-in rspec helpers | ||
# did not seem to work for this. | ||
included = false | ||
superclass.class_eval { define_method(:included) { |_| included = true } } | ||
expect { subject }.to change { included }.from(false).to(true) | ||
end | ||
|
||
it 'includes Adamantium into the descendant' do | ||
subject | ||
expect(descendant.included_modules).to include(Adamantium) | ||
end | ||
end |