# frozen_string_literal: true require "simplecov" SimpleCov.start do add_filter "/test/" enable_coverage :branch end require "em_promise" require "fiber" require "minitest/autorun" require "rantly/minitest_extensions" require "webmock/minitest" begin require "pry-rescue/minitest" require "pry-reload" module Minitest class Test alias old_capture_exceptions capture_exceptions def capture_exceptions old_capture_exceptions do yield rescue Minitest::Skip => e failures << e end end end end rescue LoadError # Just helpers for dev, no big deal if missing nil end require "backend_sgx" CONFIG = { sgx: "sgx", component: { jid: "component" }, creds: { account: "test_bw_account", username: "test_bw_user", password: "test_bw_password" }, activation_amount: 1, plans: [ { name: "test_usd", currency: :USD, monthly_price: 1000 }, { name: "test_bad_currency", currency: :BAD } ], braintree: { merchant_accounts: { USD: "merchant_usd" } }, credit_card_url: ->(*) { "http://creditcard.example.com" } }.freeze BACKEND_SGX = Minitest::Mock.new(BackendSgx.new) BLATHER = Class.new { def <<(*); end }.new.freeze class Matching def initialize(&block) @block = block end def ===(other) @block.call(other) end end class PromiseMock < Minitest::Mock def then yield self end end module EventMachine class << self # Patch EM.add_timer to be instant in tests alias old_add_timer add_timer def add_timer(*args, &block) args[0] = 0 old_add_timer(*args, &block) end end end module Minitest class Test def self.property(m, &block) define_method("test_#{m}") do property_of(&block).check { |args| send(m, *args) } end end def self.em(m) alias_method "raw_#{m}", m define_method(m) do EM.run do Fiber.new { begin send("raw_#{m}") ensure EM.stop end }.resume end end end end end