Created
September 6, 2017 13:41
-
-
Save jaimerson/cf997cbde7699e4543801d9748c7668f to your computer and use it in GitHub Desktop.
Interface Implementation Test
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
require 'rspec/autorun' | |
class Parent | |
def self.descendants | |
ObjectSpace.each_object(Class).select { |klass| klass < self } | |
end | |
def foo | |
fail NotImplementedError | |
end | |
end | |
class ChildFoo < Parent | |
def foo | |
'ha' | |
end | |
end | |
class ChildBar < Parent | |
def foo | |
'bar' | |
end | |
end | |
RSpec.describe Parent do | |
described_class.descendants.each do |child| | |
context child.name do | |
it 'implements #foo' do | |
expect { child.new.foo }.not_to raise_error | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment