Permalink
Browse files

Fix AbstractType::ClassMethods#abstract_method spec to kill mutation

  • Loading branch information...
dkubb committed Jan 19, 2013
1 parent cd84b5a commit b925d091c52cb6b4549015e3aab2552cae04ec01
Showing with 31 additions and 16 deletions.
  1. +31 −16 spec/unit/abstract_type/class_methods/abstract_method_spec.rb
@@ -3,31 +3,46 @@
require 'spec_helper'
describe AbstractType::ClassMethods, '#abstract_method' do
subject { object.some_method }
subject { object.abstract_method(:some_method) }
let(:abstract_type) do
Class.new do
include AbstractType
abstract_method :some_method
end
end
let(:class_under_test) do
Class.new(abstract_type)
end
let(:object) { Class.new { include AbstractType } }
let(:subclass) { Class.new(object) }
before do
TheClassName = class_under_test
Subclass = subclass
end
after do
Object.class_eval { remove_const(:TheClassName) }
Object.class_eval { remove_const(:Subclass) }
end
let(:object) { class_under_test.new }
it { should equal(object) }
it 'creates an abstract method' do
expect { subject }.to raise_error(NotImplementedError,'TheClassName#some_method is not implemented')
expect { subject }.to change { subclass.method_defined?(:some_method) }.
from(false).
to(true)
end
specification = proc do
subject
begin
subclass.new.some_method
rescue NotImplementedError => error
error.message.should == 'Subclass#some_method is not implemented'
file, line = error.backtrace.first.split(':')[0, 2]
file.should eql(File.expand_path('../../../../../lib/abstract_type.rb', __FILE__))
line.to_i.should be(111)
else
raise 'expected error not raised'
end
end
it 'sets the file and line number properly' do
if RUBY_PLATFORM.include?('java')
pending('Kernel#caller returns the incorrect line number in JRuby', &specification)
else
instance_eval(&specification)
end
end
end

0 comments on commit b925d09

Please sign in to comment.