1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/lib/shoulda/matchers/doublespeak/object_double.rb
Kapil Sachdev cdcef128cf fix(rubocop): Add trailing comma in args, Hash and Arrays [ci skip]
- Satisfies Style/TrailingCommaInArguments, 
Style/TrailingCommaInArrayLiteral and Style/TrailingCommaInHashLiteral
2020-11-03 10:05:25 -07:00

43 lines
923 B
Ruby

module Shoulda
module Matchers
module Doublespeak
# @private
class ObjectDouble < BasicObject
attr_reader :calls
def initialize
@calls = []
@calls_by_method_name = {}
end
def calls_to(method_name)
@calls_by_method_name[method_name] || []
end
def respond_to?(_name, _include_private = nil)
true
end
def respond_to_missing?(_name, _include_all)
true
end
def method_missing(method_name, *args, &block)
call = MethodCall.new(
method_name: method_name,
args: args,
block: block,
caller: ::Kernel.caller,
)
calls << call
(calls_by_method_name[method_name] ||= []) << call
nil
end
protected
attr_reader :calls_by_method_name
end
end
end
end