Skip to content
Browse files

Killed the mutants

  • Loading branch information...
1 parent 62ae009 commit 667fbda325ec75f6c0573b087ca03d9d4da48836 @misfo misfo committed Oct 5, 2013
View
20 spec/shared/create_new_method_shared_spec.rb
@@ -0,0 +1,20 @@
+# encoding: utf-8
+
+shared_examples 'AbstractType.create_new_method' do
+ context 'called on a subclass' do
+ let(:object) { Class.new(abstract_type) }
+
+ it { should be_instance_of(object) }
+ end
+
+ context 'called on the class' do
+ let(:object) { abstract_type }
+
+ specify do
+ expect { subject }.to raise_error(
+ NotImplementedError,
+ "#{object} is an abstract type"
+ )
+ end
+ end
+end
View
6 spec/unit/abstract_type/abstract_method_declarations/included_spec.rb
@@ -16,6 +16,12 @@
.to include(described_class::AbstractMethodDeclarations)
end
+ it 'overrides the new singleton method' do
+ expect(klass.method(:new).owner).to eq(Class)
+ klass.send(:include, subject)
+ expect(klass.method(:new).owner).to eq(klass.singleton_class)
+ end
+
it 'delegates to the ancestor' do
included_ancestor = false
subject.extend Module.new {
View
56 spec/unit/abstract_type/module_methods/create_new_method_spec.rb
@@ -16,65 +16,39 @@ def initialize(foo)
end
end
- context 'called on a subclass' do
- let(:object) { Class.new(abstract_type) }
+ it_behaves_like 'AbstractType.create_new_method'
+ end
- it { should be_instance_of(object) }
- end
+ context 'with a block' do
+ subject { object.new(:foo) { nil } }
- context 'called on the class' do
- let(:object) { abstract_type }
+ let(:abstract_type) do
+ Class.new do
+ include AbstractType
- specify do
- expect { subject }.to raise_error(
- NotImplementedError,
- "#{object} is an abstract type"
- )
+ def initialize(foo)
+ @foo = foo
+ yield
+ end
end
end
+
+ it_behaves_like 'AbstractType.create_new_method'
end
context 'without arguments' do
subject { object.new }
let(:abstract_type) { Class.new { include AbstractType } }
- context 'called on a subclass' do
- let(:object) { Class.new(abstract_type) }
-
- it { should be_instance_of(object) }
- end
-
- context 'called on the class' do
- let(:object) { abstract_type }
-
- specify do
- expect { subject }.to raise_error(
- NotImplementedError,
- "#{object} is an abstract type"
- )
- end
- end
+ it_behaves_like 'AbstractType.create_new_method'
end
context 'on an class that doesn\'t have Object as its superclass' do
subject { object.new }
let(:abstract_type) { Class.new(RuntimeError) { include AbstractType } }
- context 'called on a subclass' do
- let(:object) { Class.new(abstract_type) }
-
- it { should be_instance_of(object) }
- end
-
- context 'called on the class' do
- let(:object) { abstract_type }
-
- specify do
- expect { subject }
- .to raise_error(NotImplementedError, "#{object} is an abstract type")
- end
- end
+ it_behaves_like 'AbstractType.create_new_method'
end
end

0 comments on commit 667fbda

Please sign in to comment.
Something went wrong with that request. Please try again.