Created
February 15, 2013 13:57
-
-
Save wm/4960520 to your computer and use it in GitHub Desktop.
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
describe 'simple object' do | |
class A | |
def initialize | |
@c = 'ccc' | |
@d = 'ddd' | |
end | |
def default | |
'aaa' | |
end | |
end | |
module B | |
def self.extended(base) | |
base.class.send(:define_method, :c) do | |
@c | |
end | |
class << base | |
define_method(:d) do | |
@d | |
end | |
end | |
end | |
def default | |
'bbb' | |
end | |
end | |
a = A.new | |
b = A.new | |
c = A.new | |
describe 'a' do | |
it 'has the original default' do | |
expect(a.default).to eq 'aaa' | |
end | |
it 'does not have the extended methods' do | |
expect { a.c }.to raise_error Exception | |
expect { a.d }.to raise_error Exception | |
end | |
end | |
describe 'a' do | |
it 'has the updated default' do | |
b.extend B | |
expect(b.default).to eq 'bbb' | |
end | |
it 'has the extended methods' do | |
expect(b.c).to eq 'ccc' | |
expect(b.d).to eq 'ddd' | |
end | |
end | |
describe 'a' do | |
it 'has the original default' do | |
expect(c.default).to eq 'aaa' | |
end | |
it 'has the extended c method' do | |
expect(c.c).to eq 'ccc' | |
end | |
it 'does not have the extended d method' do | |
expect{ c.d }.to raise_error Exception | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment