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
35require "backend_sgx"
36
37CONFIG = {
38 sgx: "sgx",
39 component: {
40 jid: "component"
41 },
42 creds: {
43 account: "test_bw_account",
44 username: "test_bw_user",
45 password: "test_bw_password"
46 },
47 catapult: {
48 user: "catapult_user",
49 token: "catapult_token",
50 secret: "catapult_secret",
51 application_id: "catapult_app"
52 },
53 activation_amount: 1,
54 plans: [
55 {
56 name: "test_usd",
57 currency: :USD,
58 monthly_price: 1000
59 },
60 {
61 name: "test_bad_currency",
62 currency: :BAD
63 }
64 ],
65 braintree: {
66 merchant_accounts: {
67 USD: "merchant_usd"
68 }
69 },
70 credit_card_url: ->(*) { "http://creditcard.example.com" }
71}.freeze
72
73BACKEND_SGX = Minitest::Mock.new(BackendSgx.new)
74
75BLATHER = Class.new {
76 def <<(*); end
77}.new.freeze
78
79class Matching
80 def initialize(&block)
81 @block = block
82 end
83
84 def ===(other)
85 @block.call(other)
86 end
87end
88
89class PromiseMock < Minitest::Mock
90 def then(succ=nil, _=nil)
91 if succ
92 succ.call(self)
93 else
94 yield self
95 end
96 end
97end
98
99module EventMachine
100 class << self
101 # Patch EM.add_timer to be instant in tests
102 alias old_add_timer add_timer
103 def add_timer(*args, &block)
104 args[0] = 0
105 old_add_timer(*args, &block)
106 end
107 end
108end
109
110module Minitest
111 class Test
112 def self.property(m, &block)
113 define_method("test_#{m}") do
114 property_of(&block).check { |args| send(m, *args) }
115 end
116 end
117
118 def self.em(m)
119 alias_method "raw_#{m}", m
120 define_method(m) do
121 EM.run do
122 Fiber.new {
123 begin
124 send("raw_#{m}")
125 ensure
126 EM.stop
127 end
128 }.resume
129 end
130 end
131 end
132 end
133end