File: test_unit_assert_spy_called.rb

package info (click to toggle)
ruby-flexmock 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: ruby: 7,572; makefile: 6
file content (41 lines) | stat: -rw-r--r-- 1,156 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
35
36
37
38
39
40
41
require 'flexmock/spy_describers'

class FlexMock
  module TestUnitAssertions
    include FlexMock::SpyDescribers

    def assert_spy_called(spy, method_name, *args, **kw)
      _assert_spy_called(false, spy, method_name, *args, **kw)
    end

    def assert_spy_not_called(spy, method_name, *args, **kw)
      _assert_spy_called(true, spy, method_name, *args, **kw)
    end

    private

    def _assert_spy_called(negative, spy, method_name, *args, **kw)
      options = {}
      if method_name.is_a?(Hash)
        options = method_name
        method_name = args.shift
      end

      # Prior to ruby3, kw args would be matched in *args
      # thus, expecting any args (:_) implied also expecting
      # any kw args.
      kw = :_ if args == [:_]

      args = nil if args == [:_]
      kw = nil if kw == :_
      bool = spy.flexmock_received?(method_name, args, kw, options)
      if negative
        bool = !bool
        message = describe_spy_negative_expectation(spy, method_name, args, kw, options)
      else
        message = describe_spy_expectation(spy, method_name, args, kw, options)
      end
      assert bool, message
    end
  end
end