Method: FlexMock.format_args

Defined in:
lib/flexmock/core_class_methods.rb

.format_args(args, kw) ⇒ Object

Class method to format a list of args (the part between the parenthesis).



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/flexmock/core_class_methods.rb', line 87

def format_args(args, kw)
  args =
    if args
      args = args.map do |a|
        FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
          a.inspect
        end
      end
      args.join(', ')
    else
      "*args"
    end

  kw =
    if kw.kind_of? HashMatcher
      kw.inspect
    elsif kw && !kw.empty?
      kw = kw.transform_values do |v|
        FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
          v.inspect
        end
      end
      kw.map { |k, v| "#{k}: #{v}" }.join(', ')
    elsif kw.nil?
      # Don't append **kwargs to signature if ruby version < 3
      # in order to not break existing code still on ruby2
      "**kwargs" unless RUBY_VERSION < "3"
    end

  [(args unless args.empty?), kw].compact.join(", ")
end