File: common.rb

package info (click to toggle)
ruby-sanitize 4.6.6-2.1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 528 kB
  • sloc: ruby: 2,837; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 673 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# encoding: utf-8
gem 'minitest'
require 'minitest/autorun'

require 'sanitize'

# Helper to stub an instance method. Shamelessly stolen from
# https://github.com/codeodor/minitest-stub_any_instance/
class Object
  def self.stub_instance(name, value, &block)
    old_method = "__stubbed_method_#{name}__"

    class_eval do
      alias_method old_method, name

      define_method(name) do |*args|
        if value.respond_to?(:call) then
          value.call(*args)
        else
          value
        end
      end
    end

    yield

  ensure
    class_eval do
      undef_method name
      alias_method name, old_method
      undef_method old_method
    end
  end
end