Skip to content

Instantly share code, notes, and snippets.

@jaimerson
Created September 6, 2017 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaimerson/cf997cbde7699e4543801d9748c7668f to your computer and use it in GitHub Desktop.
Save jaimerson/cf997cbde7699e4543801d9748c7668f to your computer and use it in GitHub Desktop.
Interface Implementation Test
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