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
73BLATHER = Class.new {
74 def <<(*); end
75}.new.freeze
76
77class Matching
78 def initialize(&block)
79 @block = block
80 end
81
82 def ===(other)
83 @block.call(other)
84 end
85end
86
87class PromiseMock < Minitest::Mock
88 def then(succ=nil, _=nil)
89 if succ
90 succ.call(self)
91 else
92 yield self
93 end
94 end
95end
96
97module EventMachine
98 class << self
99 # Patch EM.add_timer to be instant in tests
100 alias old_add_timer add_timer
101 def add_timer(*args, &block)
102 args[0] = 0
103 old_add_timer(*args, &block)
104 end
105 end
106end
107
108module Minitest
109 class Test
110 def self.property(m, &block)
111 define_method("test_#{m}") do
112 property_of(&block).check { |args| send(m, *args) }
113 end
114 end
115
116 def self.em(m)
117 alias_method "raw_#{m}", m
118 define_method(m) do
119 EM.run do
120 Fiber.new {
121 begin
122 send("raw_#{m}")
123 ensure
124 EM.stop
125 end
126 }.resume
127 end
128 end
129 end
130 end
131end