Skip to content

Commit

Permalink
Kill alive mutations in Adamanitum::Flat.included
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed Aug 11, 2014
1 parent dd8b0dd commit be11577
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/adamantium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def freezer
#
# @api private
def self.included(descendant)
super
descendant.instance_exec(self) do |mod|
include Adamantium
extend mod
Expand Down
38 changes: 32 additions & 6 deletions spec/unit/adamantium/flat/class_methods/included_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,41 @@
require 'spec_helper'

describe Adamantium::Flat, '.included' do
subject do
Class.new do
include Adamantium::Flat
subject { descendant.instance_exec(object) { |mod| include mod } }

let(:object) { described_class }
let(:descendant) { Class.new }
let(:superclass) { Module }

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

its(:ancestors) { should include(Adamantium) }
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 = 0
superclass.class_eval { define_method(:included) { |_| included += 1 } }
expect(included).to be(0)
subject
expect(included).to be(1)
end

it 'includes Adamantium into the descendant' do
subject
expect(descendant.included_modules).to include(Adamantium)
end

it 'extends class with Adamantium::Flat' do
expect(subject.singleton_class.included_modules).to include(described_class)
it 'extends the descendant with Adamantium::Flat' do
subject
expect(descendant.singleton_class.included_modules)
.to include(Adamantium::Flat)
end
end

0 comments on commit be11577

Please sign in to comment.