1# frozen_string_literal: true
2
3require "simplecov"
4SimpleCov.start do
5 add_filter "/test/"
6 enable_coverage :branch
7end
8
9require "em_promise"
10require "fiber"
11require "minitest/autorun"
12require "rantly/minitest_extensions"
13require "webmock/minitest"
14begin
15 require "pry-rescue/minitest"
16 require "pry-reload"
17
18 module Minitest
19 class Test
20 alias old_capture_exceptions capture_exceptions
21 def capture_exceptions
22 old_capture_exceptions do
23 yield
24 rescue Minitest::Skip => e
25 failures << e
26 end
27 end
28 end
29 end
30rescue LoadError
31 # Just helpers for dev, no big deal if missing
32 nil
33end
34
35CONFIG = {
36 sgx: "sgx",
37 component: {
38 jid: "component"
39 },
40 activation_amount: 1,
41 plans: [
42 {
43 name: "test_usd",
44 currency: :USD
45 },
46 {
47 name: "test_bad_currency",
48 currency: :BAD
49 }
50 ],
51 braintree: {
52 merchant_accounts: {
53 USD: "merchant_usd"
54 }
55 },
56 credit_card_url: ->(*) { "http://creditcard.example.com" }
57}.freeze
58
59BLATHER = Class.new {
60 def <<(*); end
61}.new.freeze
62
63class Matching
64 def initialize(&block)
65 @block = block
66 end
67
68 def ===(other)
69 @block.call(other)
70 end
71end
72
73class PromiseMock < Minitest::Mock
74 def then
75 yield self
76 end
77end
78
79module EventMachine
80 class << self
81 # Patch EM.add_timer to be instant in tests
82 alias old_add_timer add_timer
83 def add_timer(*args, &block)
84 args[0] = 0
85 old_add_timer(*args, &block)
86 end
87 end
88end
89
90module Minitest
91 class Test
92 def self.property(m, &block)
93 define_method("test_#{m}") do
94 property_of(&block).check { |args| send(m, *args) }
95 end
96 end
97
98 def self.em(m)
99 alias_method "raw_#{m}", m
100 define_method(m) do
101 EM.run do
102 Fiber.new {
103 begin
104 send("raw_#{m}")
105 ensure
106 EM.stop
107 end
108 }.resume
109 end
110 end
111 end
112 end
113end