47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/duck_typer/rspec.rb', line 47
def self.define_shared_example(name = "an interface")
::RSpec.shared_examples name do |*args, canonical: nil, namespace: nil, name: nil, type: :instance_methods, methods: nil, strict: false|
objects = namespace ? nil : args.first
if canonical
it "implements the canonical interface" do
checker = DuckTyper::CanonicalInterfaceChecker
.new(objects, canonical:, namespace:, type:, methods:, strict:, name:)
result = checker.call
if !result.match?
raise ::RSpec::Expectations::ExpectationNotMetError, result.failure_message
end
end
else
it "has compatible interfaces" do
checker = DuckTyper::BulkInterfaceChecker
.new(objects, namespace:, type:, methods:, strict:, name:)
failures = checker.call.reject(&:match?)
if failures.any?
message = failures.map(&:failure_message).join("\n")
raise ::RSpec::Expectations::ExpectationNotMetError, message
end
end
end
end
end
|