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 activation_amount: 1,
48 plans: [
49 {
50 name: "test_usd",
51 currency: :USD,
52 monthly_price: 1000
53 },
54 {
55 name: "test_bad_currency",
56 currency: :BAD
57 }
58 ],
59 braintree: {
60 merchant_accounts: {
61 USD: "merchant_usd"
62 }
63 },
64 credit_card_url: ->(*) { "http://creditcard.example.com" }
65}.freeze
66
67BACKEND_SGX = Minitest::Mock.new(BackendSgx.new)
68
69BLATHER = Class.new {
70 def <<(*); end
71}.new.freeze
72
73class Matching
74 def initialize(&block)
75 @block = block
76 end
77
78 def ===(other)
79 @block.call(other)
80 end
81end
82
83class PromiseMock < Minitest::Mock
84 def then
85 yield self
86 end
87end
88
89module EventMachine
90 class << self
91 # Patch EM.add_timer to be instant in tests
92 alias old_add_timer add_timer
93 def add_timer(*args, &block)
94 args[0] = 0
95 old_add_timer(*args, &block)
96 end
97 end
98end
99
100module Minitest
101 class Test
102 def self.property(m, &block)
103 define_method("test_#{m}") do
104 property_of(&block).check { |args| send(m, *args) }
105 end
106 end
107
108 def self.em(m)
109 alias_method "raw_#{m}", m
110 define_method(m) do
111 EM.run do
112 Fiber.new {
113 begin
114 send("raw_#{m}")
115 ensure
116 EM.stop
117 end
118 }.resume
119 end
120 end
121 end
122 end
123end