Permalink
Browse files

Support mutating a namespace class: mutate Foo::Bar#hello spec/the_sp…

…ec.rb
  • Loading branch information...
1 parent d98f888 commit f182bb4bac3f16fff1f4b6f21d0c489ef79baf89 @justinko justinko committed Feb 9, 2012
Showing with 27 additions and 21 deletions.
  1. +3 −1 lib/mutant/implementation.rb
  2. +17 −11 spec/mutant/implementation_spec.rb
  3. +7 −9 spec/mutant/mutatee_spec.rb
@@ -26,7 +26,9 @@ def method_name
end
def constant
- Object.const_get(class_name)
+ class_name.split(/::/).inject(Object) do |context, name|
+ context.const_get name
+ end
end
def all_implementations
@@ -1,17 +1,6 @@
require 'spec_helper'
describe Mutant::Implementation do
- def self.setup_thing(&block)
- before do
- Object.const_set(:Thing, Class.new)
- Object.const_get(:Thing).class_eval(&block) if block
- end
-
- after do
- Object.send(:remove_const, :Thing) if Object.const_defined?(:Thing)
- end
- end
-
describe '#scope_type' do
context 'given "Thing.alive?"' do
it 'returns :singleton' do
@@ -38,6 +27,13 @@ def self.setup_thing(&block)
Mutant::Implementation.new('Thing.alive?').class_name.should eq('Thing')
end
end
+
+ context 'given "Thing::Spirit#alive?"' do
+ it 'returns "Thing::Spirit"' do
+ Mutant::Implementation.new('Thing::Spirit#alive?').
+ class_name.should eq('Thing::Spirit')
+ end
+ end
end
describe '#method_scope' do
@@ -90,6 +86,16 @@ def self.setup_thing(&block)
implementation.constant.should eq(Thing)
end
end
+
+ context 'given "Thing::Spirit"' do
+ setup_thing { class Spirit; end }
+
+ let(:implementation) { Mutant::Implementation.new('Thing::Spirit') }
+
+ it 'returns Thing::Spirit' do
+ implementation.constant.should eq(Thing::Spirit)
+ end
+ end
end
describe '#all_implementations' do
@@ -2,24 +2,22 @@
describe Mutant::Mutatee do
describe '#rbx_method' do
- before do
- class ::Foo
- def self.bar; end
- def bar; end
- end
+ setup_thing do
+ def self.bar; end
+ def bar; end
end
- context 'given an Implementation for a singleton method' do
- let(:implementation) { Mutant::Implementation.new('Foo.bar') }
+ context 'given an implementation for a singleton method' do
+ let(:implementation) { Mutant::Implementation.new('Thing.bar') }
let(:mutatee) { Mutant::Mutatee.new(implementation) }
it 'returns a SingletonMethod' do
mutatee.rbx_method.should be_an_instance_of(Mutant::SingletonMethod)
end
end
- context 'given an Implementation for an instance method' do
- let(:implementation) { Mutant::Implementation.new('Foo#bar') }
+ context 'given an implementation for an instance method' do
+ let(:implementation) { Mutant::Implementation.new('Thing#bar') }
let(:mutatee) { Mutant::Mutatee.new(implementation) }
it 'returns an InstanceMethod' do

0 comments on commit f182bb4

Please sign in to comment.