File: extra_assertions.rb

package info (click to toggle)
ruby-zip 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,120 kB
  • sloc: ruby: 9,958; makefile: 23
file content (22 lines) | stat: -rw-r--r-- 551 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
# frozen_string_literal: true

module ExtraAssertions
  def assert_forwarded(object, method, ret_val, *expected_args)
    call_args = nil
    object.singleton_class.class_exec do
      alias_method :"#{method}_org", method
      define_method(method) do |*args|
        call_args = args
        ret_val
      end
    end

    assert_equal(ret_val, yield) # Invoke test
    assert_equal(expected_args, call_args)
  ensure
    object.singleton_class.class_exec do
      remove_method method
      alias_method method, :"#{method}_org"
    end
  end
end