Sha256: 0ccaa9aae41c05845cf00813772a21c57fda9b52686c8edf3fd1b4b07b96f03b
Contents?: true
Size: 964 Bytes
Versions: 14
Compression:
Stored size: 964 Bytes
Contents
module HooksHelper def expect_hook(event, stack = nil, payload = nil) spy_on_hook yield assert_received_with(Shipit::Hook, :emit) do |call| if call.args.first == event && (stack.nil? || call.args.second == stack) if payload.respond_to?(:call) payload.call(call.args.third) elsif payload payload == call.args.third else true end end end end def expect_no_hook(*args) spy_on_hook yield spy = Spy::Subroutine.get(Shipit::Hook, :emit) called = spy.calls.find do |call| args.map.with_index.all? { |value, index| value == call.args[index] } end matcher = args.map(&:inspect).join(', ') got = called&.args&.map(&:inspect)&.join(', ') refute called, "Expected no hook matching: (#{matcher})\n got: (#{got})" end private def spy_on_hook Spy.on(Shipit::Hook, :emit).and_call_through rescue Spy::AlreadyHookedError end end
Version data entries
14 entries across 14 versions & 1 rubygems