Skip to content

Instantly share code, notes, and snippets.

@smmr0
smmr0 / .gitconfig-organization.local
Last active August 8, 2024 20:26
Git: Organization config
[user]
name = …
email = …
signingkey =
RSpec.shared_examples_for "check interface against canonical" do |canonical_interface, classes_to_check|
classes_to_check.each do |class_to_check|
example "#{class_to_check} conforms to the required interface", :aggregate_failures do
interface_methods = canonical_interface.public_instance_methods(false)
methods_to_check = class_to_check.public_instance_methods(false)
diff = interface_methods - methods_to_check
expect(diff).to be_empty, (<<~MESSAGE).split("\n").join(" ")
Expected #{class_to_check} to be polymorphic with
RSpec.shared_examples_for "interface checker" do
def diff_for(array_1, array_2)
(array_1 - array_2) + (array_2 - array_1)
end
def arities_for(object)
object.public_methods.map do |m|
arity = object.method(m).arity
[m, arity == -1 ? anything : arity]
end