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/method_call.rb
Elliot Winkler 5347402043 Add debugging helps to Doublespeak
Why:

* When debugging #permit it's been helpful to loop through all of the
  doubles that Doublespeak has registered and spit out all of the calls
  on those doubles (specifically which arguments they've received).
* It's also been helpful to know where the methods the doubles represent
  have been called.

To satisfy the above:

* Add #calls_by_method_name to DoubleCollection
* Add #caller to MethodCall
2015-09-29 18:42:08 -06:00

44 lines
1.1 KiB
Ruby

module Shoulda
module Matchers
module Doublespeak
# @private
class MethodCall
attr_accessor :return_value
attr_reader :method_name, :args, :caller, :block, :object, :double
def initialize(args)
@method_name = args.fetch(:method_name)
@args = args.fetch(:args)
@caller = args.fetch(:caller)
@block = args[:block]
@double = args[:double]
@object = args[:object]
@return_value = nil
end
def with_return_value(return_value)
dup.tap do |call|
call.return_value = return_value
end
end
def ==(other)
other.is_a?(self.class) &&
method_name == other.method_name &&
args == other.args &&
block == other.block &&
double == other.double &&
object == other.object
end
def to_hash
{ method_name: method_name, args: args }
end
def inspect
"#<#{self.class.name} #{to_hash.inspect}>"
end
end
end
end
end