File: stubbing.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (14 lines) | stat: -rw-r--r-- 421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Specs
  def self.stub_out_class_method(mod, meth)
    meta = (class << mod; self; end)
    original_meth = "original_#{meth}".to_sym

    raise "ALREADY TRACED: #{mod}.#{meth}" if mod.respond_to?(original_meth)

    meta.send(:alias_method, original_meth, meth)
    meta.send(:define_method, meth) do |*args, &block|
      yield(*args) if block_given?
      mod.send original_meth, *args, &block
    end
  end
end