Interface matcher?

12 views
Skip to first unread message

Xavier Shay

unread,
Mar 20, 2014, 11:04:40 AM3/20/14
to rs...@googlegroups.com
Hello,

I'm toying around with a matcher to compare the interface of two classes.
I intend to use this where ever I am providing an explicit fake or stub of a class.

class MatchInterface
  def initialize(klass)
    @klass = klass
  end

  def matches?(other)
    @other = other
    @lhs = @klass.public_instance_methods
    @rhs = @other.public_instance_methods

    lhs == rhs
  end

  def failure_message
    diff = (@lhs - @rhs) + (@rhs - @lhs)
    "The following methods are different:\n#{diff.join("\n")}"
  end
end

I'd like to include
* Class methods
* Arity verification (would love to use RSpec::Support::MethodSignature for this ... might consider making it public)
* Partial interface (i.e. it doesn't implement all methods, but the ones it does are correct and valid)

Has anyone built anything like this already?

Xav
Reply all
Reply to author
Forward
0 new messages