Sha256: ee394fce58de76f35c95416c02ec1e2e9776225964964eb4ed1e337f9c8ca221

Contents?: true

Size: 971 Bytes

Versions: 27

Compression:

Stored size: 971 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 && 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

27 entries across 27 versions & 1 rubygems

Version Path
shipit-engine-0.21.0 test/helpers/hooks_helper.rb
shipit-engine-0.20.1 test/helpers/hooks_helper.rb
shipit-engine-0.20.0 test/helpers/hooks_helper.rb
shipit-engine-0.19.0 test/helpers/hooks_helper.rb
shipit-engine-0.18.1 test/helpers/hooks_helper.rb
shipit-engine-0.18.0 test/helpers/hooks_helper.rb
shipit-engine-0.17.0 test/helpers/hooks_helper.rb
shipit-engine-0.16.0 test/helpers/hooks_helper.rb
shipit-engine-0.15.0 test/helpers/hooks_helper.rb
shipit-engine-0.14.0 test/helpers/hooks_helper.rb
shipit-engine-0.13.0 test/helpers/hooks_helper.rb
shipit-engine-0.12.1 test/helpers/hooks_helper.rb
shipit-engine-0.12.0 test/helpers/hooks_helper.rb
shipit-engine-0.11.0 test/helpers/hooks_helper.rb
shipit-engine-0.10.0 test/helpers/hooks_helper.rb
shipit-engine-0.9.0 test/helpers/hooks_helper.rb
shipit-engine-0.8.9 test/helpers/hooks_helper.rb
shipit-engine-0.8.8 test/helpers/hooks_helper.rb
shipit-engine-0.8.7 test/helpers/hooks_helper.rb
shipit-engine-0.8.6 test/helpers/hooks_helper.rb