Skip to content

Instantly share code, notes, and snippets.

@wm
Created February 15, 2013 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wm/4960520 to your computer and use it in GitHub Desktop.
Save wm/4960520 to your computer and use it in GitHub Desktop.
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