Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 additions
and
82 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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
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
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
spec/unit/abstract_type/module_methods/create_new_method_spec.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe AbstractType, '.create_new_method' do | ||
context 'with arguments' do | ||
subject { object.new(:foo) } | ||
|
||
let(:abstract_type) do | ||
Class.new do | ||
include AbstractType | ||
|
||
def initialize(foo) | ||
@foo = foo | ||
end | ||
end | ||
end | ||
|
||
it_behaves_like 'AbstractType.create_new_method' | ||
end | ||
|
||
context 'with a block' do | ||
subject { object.new(:foo) { nil } } | ||
|
||
let(:abstract_type) do | ||
Class.new do | ||
include AbstractType | ||
|
||
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 } } | ||
|
||
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 } } | ||
|
||
it_behaves_like 'AbstractType.create_new_method' | ||
end | ||
end |