module RSpec::RubyContentMatchers class HaveCalls attr_reader :calls attr_accessor :method, :args def initialize(calls) @calls = calls end def matches?(content) calls.each_pair do |method, args| @method = method.to_s @args = args return false if (content =~ /#{method}\s+#{args_expr}/m) == nil end true end def failure_message return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args "Expected there to be a call to #{method}, but there wasn't" end def negative_failure_message return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args "Did not expect there to be a call to #{method}, but there was" end protected def args_expr args ? "(\()?\s*#{args}\s*(\))?" : '' end end def have_calls(calls) HaveCalls.new(calls) end end