Sha256: f022ee719403354519d951706d5c774a68ff4883e8109b0a11555601852af2eb

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 Bytes

Contents

require "rubygems"
require "metaid"

module Override
  def override object, methods
    methods.each do |method, result|
      result.respond_to?(:to_proc) ?
        object.meta_def(method, &result.to_proc) :
        object.meta_def(method) { |*_| result }
    end
    object
  end

  def expect object, method, options
    expectation = lambda do |*params|
      unless params == options[:with]
        raise ExpectationError.new(options[:with], params)
      end
      options[:return]
    end
    override(object, method => expectation)
  end

  class ExpectationError < ArgumentError
    def initialize(expected, actual)
      super("Expected #{expected.inspect}, got #{actual.inspect}")
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
soveran-override-0.0.9 lib/override.rb
override-0.0.9 lib/override.rb