stripe-ruby-mock 4.1.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +16 -13
- data/Appraisals +7 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/README.md +9 -3
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/stripe_12.gemfile +13 -0
- data/gemfiles/stripe_12.gemfile.lock +60 -0
- data/gemfiles/stripe_13.gemfile +13 -0
- data/gemfiles/stripe_13.gemfile.lock +60 -0
- data/lib/stripe_mock/api/client.rb +12 -4
- data/lib/stripe_mock/api/instance.rb +5 -3
- data/lib/stripe_mock/client.rb +2 -3
- data/lib/stripe_mock/compat.rb +29 -0
- data/lib/stripe_mock/data.rb +8 -0
- data/lib/stripe_mock/instance.rb +44 -3
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
- data/lib/stripe_mock/util.rb +6 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock.rb +1 -1
- data/spec/instance_spec.rb +7 -2
- data/spec/list_spec.rb +1 -1
- data/spec/server_spec.rb +12 -3
- data/spec/shared_stripe_examples/account_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +1 -1
- data/spec/shared_stripe_examples/setup_intent_examples.rb +5 -1
- data/spec/shared_stripe_examples/subscription_examples.rb +1 -1
- data/spec/shared_stripe_examples/transfer_examples.rb +10 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/stripe_mock_spec.rb +35 -13
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25863512f9198c5d281a21813ce21357d94d9cb39a346a65006135ba3baafd7d
|
4
|
+
data.tar.gz: 718a79b250972169ba5fa7f4c6c766cfee25038b1b730cb39758086a0f40c557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2aac810a519355990df689750f9103f4c44b1ca95de9ba2a23155c61338d48ed7322290ab0fcb322def1a49b80b51b9bbba9632f3f26bc36ca5faf70e034dd7
|
7
|
+
data.tar.gz: 14a7042d3391b7aabfaf7912f88fd57fd2b808985e26cad37fd51cd2e320981fd4f3a51f6e045caed56a9644a2bbae47232d9f553bd950e49f55b537f7401050
|
@@ -9,9 +9,9 @@ name: Tests
|
|
9
9
|
|
10
10
|
on:
|
11
11
|
push:
|
12
|
-
branches: [
|
12
|
+
branches: ["master"]
|
13
13
|
pull_request:
|
14
|
-
branches: [
|
14
|
+
branches: ["master"]
|
15
15
|
|
16
16
|
permissions:
|
17
17
|
contents: read
|
@@ -20,16 +20,19 @@ jobs:
|
|
20
20
|
test:
|
21
21
|
runs-on: ubuntu-latest
|
22
22
|
strategy:
|
23
|
+
fail-fast: false
|
23
24
|
matrix:
|
24
|
-
ruby: [
|
25
|
+
ruby: ["3.1", "3.2", "3.3"]
|
26
|
+
gemfile: ["stripe_12", "stripe_13"]
|
27
|
+
env:
|
28
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
25
29
|
steps:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
run: bundle exec rspec
|
30
|
+
- uses: actions/checkout@v4
|
31
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
32
|
+
uses: ruby/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby }}
|
35
|
+
- name: Install dependencies
|
36
|
+
run: bundle install
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rspec
|
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### 5.0.0
|
4
|
+
- [#919](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/919) Add capabilities to mock account data [@cazwazacz](https://github.com/cazwazacz)
|
5
|
+
- [#931](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/931) Support Stripe version 13 + 12 [@gabrieltaylor](https://github.com/gabrieltaylor)
|
6
|
+
|
3
7
|
### 4.1.0 (2025-04-24)
|
4
8
|
- [#920](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/920) Adds DRB as a dependency in preparation to Ruby 3.4.0 [@lucascppessoa](https://github.com/lucascppessoa)
|
5
9
|
- [#927](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/927) Allow :cancel_url nil in create Checkout Session [@shu-illy](https://github.com/shu-illy)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,8 @@ In your gemfile:
|
|
18
18
|
|
19
19
|
We have [changelog](https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md). It's first attempt. Feel free to update it and suggest to a new format of it.
|
20
20
|
|
21
|
+
version `5.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/931) - we support stripe > 5 and <= 13 for now and try to follow the newest API version.
|
22
|
+
|
21
23
|
version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) - we support stripe > 5 and < 6 for now and try to follow the newest API version. But if you still use older versions please [read](https://github.com/stripe-ruby-mock/stripe-ruby-mock#specifications).
|
22
24
|
|
23
25
|
## Features
|
@@ -29,12 +31,12 @@ version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/strip
|
|
29
31
|
|
30
32
|
### Requirements
|
31
33
|
|
32
|
-
* ruby >=
|
33
|
-
* stripe > 5 &
|
34
|
+
* ruby >= 3.0.0
|
35
|
+
* stripe > 5 & <= 13
|
34
36
|
|
35
37
|
### Specifications
|
36
38
|
|
37
|
-
**STRIPE API TARGET VERSION:**
|
39
|
+
**STRIPE API TARGET VERSION:** 2024-06-20 (master) - we try, but some features are not implemented yet.
|
38
40
|
|
39
41
|
Older API version branches:
|
40
42
|
|
@@ -408,6 +410,10 @@ This will help ensure that the problem remains fixed in future updates.
|
|
408
410
|
|
409
411
|
Note: You may need to `ulimit -n 4048` before running the test suite to get all tests to pass.
|
410
412
|
|
413
|
+
### Dependency updates
|
414
|
+
|
415
|
+
When modifications are made to dependencies in addition to the changes to the Gemfile, Gemfile.lock and stripe-ruby-mock.gemspec you must also run `bundle exec appraisal update` to update the gemfiles specific to Stripe version 12 and Stripe version 13.
|
416
|
+
|
411
417
|
## Copyright
|
412
418
|
|
413
419
|
Copyright (c) 2013 Gilbert
|
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
stripe-ruby-mock (4.0.0)
|
5
|
+
dante (>= 0.2.0)
|
6
|
+
drb (>= 2.0.4, < 3)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
stripe (> 5, < 14)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
appraisal (2.5.0)
|
14
|
+
bundler
|
15
|
+
rake
|
16
|
+
thor (>= 0.14.0)
|
17
|
+
daemons (1.4.1)
|
18
|
+
dante (0.2.0)
|
19
|
+
diff-lcs (1.6.1)
|
20
|
+
dotenv (2.8.1)
|
21
|
+
drb (2.2.1)
|
22
|
+
eventmachine (1.2.7)
|
23
|
+
multi_json (1.15.0)
|
24
|
+
rack (2.2.13)
|
25
|
+
rake (13.2.1)
|
26
|
+
rspec (3.13.0)
|
27
|
+
rspec-core (~> 3.13.0)
|
28
|
+
rspec-expectations (~> 3.13.0)
|
29
|
+
rspec-mocks (~> 3.13.0)
|
30
|
+
rspec-core (3.13.3)
|
31
|
+
rspec-support (~> 3.13.0)
|
32
|
+
rspec-expectations (3.13.3)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.13.0)
|
35
|
+
rspec-mocks (3.13.2)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.13.0)
|
38
|
+
rspec-support (3.13.2)
|
39
|
+
stripe (12.6.0)
|
40
|
+
thin (1.8.2)
|
41
|
+
daemons (~> 1.0, >= 1.0.9)
|
42
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
43
|
+
rack (>= 1, < 3)
|
44
|
+
thor (1.3.2)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
x86_64-darwin-22
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
appraisal
|
52
|
+
dotenv
|
53
|
+
rake
|
54
|
+
rspec (~> 3.13.0)
|
55
|
+
stripe (= 12.6.0)
|
56
|
+
stripe-ruby-mock!
|
57
|
+
thin (~> 1.8.1)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.6.8
|
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
stripe-ruby-mock (4.0.0)
|
5
|
+
dante (>= 0.2.0)
|
6
|
+
drb (>= 2.0.4, < 3)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
stripe (> 5, < 14)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
appraisal (2.5.0)
|
14
|
+
bundler
|
15
|
+
rake
|
16
|
+
thor (>= 0.14.0)
|
17
|
+
daemons (1.4.1)
|
18
|
+
dante (0.2.0)
|
19
|
+
diff-lcs (1.6.1)
|
20
|
+
dotenv (2.8.1)
|
21
|
+
drb (2.2.1)
|
22
|
+
eventmachine (1.2.7)
|
23
|
+
multi_json (1.15.0)
|
24
|
+
rack (2.2.13)
|
25
|
+
rake (13.2.1)
|
26
|
+
rspec (3.13.0)
|
27
|
+
rspec-core (~> 3.13.0)
|
28
|
+
rspec-expectations (~> 3.13.0)
|
29
|
+
rspec-mocks (~> 3.13.0)
|
30
|
+
rspec-core (3.13.3)
|
31
|
+
rspec-support (~> 3.13.0)
|
32
|
+
rspec-expectations (3.13.3)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.13.0)
|
35
|
+
rspec-mocks (3.13.2)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.13.0)
|
38
|
+
rspec-support (3.13.2)
|
39
|
+
stripe (13.4.0)
|
40
|
+
thin (1.8.2)
|
41
|
+
daemons (~> 1.0, >= 1.0.9)
|
42
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
43
|
+
rack (>= 1, < 3)
|
44
|
+
thor (1.3.2)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
x86_64-darwin-22
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
appraisal
|
52
|
+
dotenv
|
53
|
+
rake
|
54
|
+
rspec (~> 3.13.0)
|
55
|
+
stripe (= 13.4.0)
|
56
|
+
stripe-ruby-mock!
|
57
|
+
thin (~> 1.8.1)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.6.8
|
@@ -8,7 +8,9 @@ module StripeMock
|
|
8
8
|
return false if @state == 'live'
|
9
9
|
return @client unless @client.nil?
|
10
10
|
|
11
|
-
|
11
|
+
Compat.client.send(:define_method, Compat.method) do |*args, **keyword_args|
|
12
|
+
StripeMock.redirect_to_mock_server(*args, **keyword_args)
|
13
|
+
end
|
12
14
|
@client = StripeMock::Client.new(port)
|
13
15
|
@state = 'remote'
|
14
16
|
@client
|
@@ -27,7 +29,14 @@ module StripeMock
|
|
27
29
|
|
28
30
|
private
|
29
31
|
|
30
|
-
def self.redirect_to_mock_server(
|
32
|
+
def self.redirect_to_mock_server(*args, **kwargs)
|
33
|
+
if args.length == 2 && kwargs.key?(:api_key) # Legacy signature
|
34
|
+
method, url = args
|
35
|
+
elsif args.length == 6 # New signature
|
36
|
+
method, url, _base_address, _params, _opts, _usage = args
|
37
|
+
else
|
38
|
+
raise ArgumentError, "Invalid arguments for mock_request"
|
39
|
+
end
|
31
40
|
handler = Instance.handler_for_method_url("#{method} #{url}")
|
32
41
|
|
33
42
|
if mock_error = client.error_queue.error_for_handler_name(handler[:name])
|
@@ -35,7 +44,6 @@ module StripeMock
|
|
35
44
|
raise mock_error
|
36
45
|
end
|
37
46
|
|
38
|
-
Stripe::Util.symbolize_names client.mock_request(
|
47
|
+
Stripe::Util.symbolize_names client.mock_request(*args, **kwargs)
|
39
48
|
end
|
40
|
-
|
41
49
|
end
|
@@ -2,12 +2,14 @@ module StripeMock
|
|
2
2
|
|
3
3
|
@state = 'ready'
|
4
4
|
@instance = nil
|
5
|
-
@original_execute_request_method =
|
5
|
+
@original_execute_request_method = Compat.client.instance_method(Compat.method)
|
6
6
|
|
7
7
|
def self.start
|
8
8
|
return false if @state == 'live'
|
9
9
|
@instance = instance = Instance.new
|
10
|
-
|
10
|
+
Compat.client.send(:define_method, Compat.method) { |*args, **keyword_args|
|
11
|
+
instance.mock_request(*args, **keyword_args)
|
12
|
+
}
|
11
13
|
@state = 'local'
|
12
14
|
end
|
13
15
|
|
@@ -29,7 +31,7 @@ module StripeMock
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def self.restore_stripe_execute_request_method
|
32
|
-
|
34
|
+
Compat.client.send(:define_method, Compat.method, @original_execute_request_method)
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.instance; @instance; end
|
data/lib/stripe_mock/client.rb
CHANGED
@@ -13,9 +13,9 @@ module StripeMock
|
|
13
13
|
@state = 'ready'
|
14
14
|
end
|
15
15
|
|
16
|
-
def mock_request(
|
16
|
+
def mock_request(*args, **kwargs)
|
17
17
|
timeout_wrap do
|
18
|
-
@pipe.mock_request(
|
18
|
+
@pipe.mock_request(*args, **kwargs).tap {|result|
|
19
19
|
response, api_key = result
|
20
20
|
if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
|
21
21
|
args, keyword_args = response[:error_params].first(2), response[:error_params].last
|
@@ -124,5 +124,4 @@ module StripeMock
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
128
127
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module Compat
|
3
|
+
def self.stripe_gte_13?
|
4
|
+
Gem::Version.new(Stripe::VERSION) >= Gem::Version.new('13.0.0')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.method
|
8
|
+
return :execute_request unless stripe_gte_13?
|
9
|
+
|
10
|
+
:execute_request_internal
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.client
|
14
|
+
return Stripe::StripeClient unless stripe_gte_13?
|
15
|
+
|
16
|
+
Stripe::APIRequestor
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.client_instance
|
20
|
+
@client ||= client.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.active_client
|
24
|
+
return client.active_client unless stripe_gte_13?
|
25
|
+
|
26
|
+
client.active_requestor
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -11,6 +11,14 @@ module StripeMock
|
|
11
11
|
display_name: "Stripe.com",
|
12
12
|
timezone: "US/Pacific",
|
13
13
|
details_submitted: false,
|
14
|
+
capabilities: {
|
15
|
+
bank_transfer_payments: "active",
|
16
|
+
card_payments: "active",
|
17
|
+
ideal_payments: "active",
|
18
|
+
sepa_bank_transfer_payments: "active",
|
19
|
+
sepa_debit_payments:"active",
|
20
|
+
transfers:"active"
|
21
|
+
},
|
14
22
|
charges_enabled: false,
|
15
23
|
payouts_enabled: false,
|
16
24
|
currencies_supported: [
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -111,7 +111,23 @@ module StripeMock
|
|
111
111
|
@base_strategy = TestStrategies::Base.new
|
112
112
|
end
|
113
113
|
|
114
|
-
def mock_request(
|
114
|
+
def mock_request(*args, **kwargs)
|
115
|
+
if args.length == 2 && kwargs.key?(:api_key) # Legacy signature
|
116
|
+
method, url = args
|
117
|
+
api_key = kwargs[:api_key]
|
118
|
+
params = kwargs[:params] || {}
|
119
|
+
headers = kwargs[:headers] || {}
|
120
|
+
elsif args.length == 6 # New signature
|
121
|
+
method, url, base_address, params, opts, usage = args
|
122
|
+
client = Compat.client_instance
|
123
|
+
config = client.send(:config)
|
124
|
+
opts = Stripe::RequestOptions.merge_config_and_opts(config, opts)
|
125
|
+
headers = client.send(:request_headers, method, Stripe::Util.get_api_mode(url), opts)
|
126
|
+
headers = headers.transform_keys { |key| Util.snake_case(key).to_sym }
|
127
|
+
else
|
128
|
+
raise ArgumentError, "Invalid arguments for mock_request"
|
129
|
+
end
|
130
|
+
|
115
131
|
return {} if method == :xtest
|
116
132
|
|
117
133
|
api_key ||= (Stripe.api_key || DUMMY_API_KEY)
|
@@ -134,12 +150,21 @@ module StripeMock
|
|
134
150
|
else
|
135
151
|
res = self.send(handler[:name], handler[:route], method_url, params, headers)
|
136
152
|
puts " [res] #{res}" if @debug == true
|
137
|
-
|
153
|
+
|
154
|
+
if Compat.stripe_gte_13?
|
155
|
+
[to_net_http(res, headers), opts]
|
156
|
+
else
|
157
|
+
[to_faraday_hash(res), api_key]
|
158
|
+
end
|
138
159
|
end
|
139
160
|
else
|
140
161
|
puts "[StripeMock] Warning : Unrecognized endpoint + method : [#{method} #{url}]"
|
141
162
|
puts "[StripeMock] params: #{params}" unless params.empty?
|
142
|
-
|
163
|
+
if Compat.stripe_gte_13?
|
164
|
+
[{}, opts]
|
165
|
+
else
|
166
|
+
[{}, api_key]
|
167
|
+
end
|
143
168
|
end
|
144
169
|
end
|
145
170
|
|
@@ -224,6 +249,22 @@ module StripeMock
|
|
224
249
|
response.new(hash)
|
225
250
|
end
|
226
251
|
|
252
|
+
def to_net_http(hash, headers)
|
253
|
+
headers = headers.slice(*%w[request-id stripe-account-id stripe-version stripe-version-stabl idempotency-key content-type])
|
254
|
+
fake_net_http_response(code: "200", message: "OK", body: hash.to_json, headers: headers)
|
255
|
+
end
|
256
|
+
|
257
|
+
def fake_net_http_response(code: "200", message: "OK", body: "{}", headers: {})
|
258
|
+
response_class = Net::HTTPResponse::CODE_TO_OBJ[code]
|
259
|
+
response = response_class.new("1.1", code, message)
|
260
|
+
headers.each { |k, v| response[k] = v }
|
261
|
+
response.instance_variable_set(:@body, body)
|
262
|
+
response.instance_variable_set(:@read, true)
|
263
|
+
|
264
|
+
response
|
265
|
+
end
|
266
|
+
|
267
|
+
|
227
268
|
def calculate_fees(params)
|
228
269
|
application_fee = params[:application_fee] || 0
|
229
270
|
params[:fee] = processing_fee(params[:amount]) + application_fee
|
data/lib/stripe_mock/util.rb
CHANGED
@@ -40,5 +40,11 @@ module StripeMock
|
|
40
40
|
old_param.merge(new_param)
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.snake_case(str)
|
44
|
+
str.gsub(/([a-z])([A-Z])/, '\1_\2') # Convert camelCase to snake_case
|
45
|
+
.gsub(/[-]/, '_') # Convert kebab-case to snake_case
|
46
|
+
.downcase # Ensure all characters are lowercase
|
47
|
+
end
|
48
|
+
|
43
49
|
end
|
44
50
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
data/lib/stripe_mock.rb
CHANGED
data/spec/instance_spec.rb
CHANGED
@@ -20,8 +20,13 @@ describe StripeMock::Instance do
|
|
20
20
|
"type" => "service"
|
21
21
|
)
|
22
22
|
res, api_key = StripeMock.instance.mock_request('post', '/v1/products', api_key: 'api_key', params: symbol_params)
|
23
|
-
|
24
|
-
|
23
|
+
if StripeMock::Compat.stripe_gte_13?
|
24
|
+
expect(JSON.parse(res.body)["name"]).to eq('Symbol Product')
|
25
|
+
expect(JSON.parse(res.body)["type"]).to eq('service')
|
26
|
+
else
|
27
|
+
expect(res.data[:name]).to eq('Symbol Product')
|
28
|
+
expect(res.data[:type]).to eq('service')
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
it "exits gracefully on an unrecognized handler url" do
|
data/spec/list_spec.rb
CHANGED
@@ -149,7 +149,7 @@ describe StripeMock::Data::List do
|
|
149
149
|
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
150
150
|
list = StripeMock::Data::List.new(data, starting_after: "test_ch_unknown")
|
151
151
|
|
152
|
-
expect { list.to_h }.to raise_error
|
152
|
+
expect { list.to_h }.to raise_error(RuntimeError, "No such object id: test_ch_unknown")
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
data/spec/server_spec.rb
CHANGED
@@ -54,11 +54,20 @@ describe 'StripeMock Server', :mock_server => true do
|
|
54
54
|
|
55
55
|
|
56
56
|
it "returns a response with symbolized hash keys" do
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
unless StripeMock::Compat.stripe_gte_13?
|
58
|
+
stripe_helper.create_plan(id: 'x', product: product.id)
|
59
|
+
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
|
60
|
+
response.data.keys.each {|k| expect(k).to be_a(Symbol) }
|
61
|
+
end
|
60
62
|
end
|
61
63
|
|
64
|
+
it "returns a Net::HttpResponse" do
|
65
|
+
if StripeMock::Compat.stripe_gte_13?
|
66
|
+
stripe_helper.create_plan(id: 'x', product: product.id)
|
67
|
+
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', 'https://api.stripe.com', {}, {}, 'normal')
|
68
|
+
expect(response).to be_a(Net::HTTPResponse)
|
69
|
+
end
|
70
|
+
end
|
62
71
|
|
63
72
|
it "can toggle debug" do
|
64
73
|
StripeMock.toggle_debug(true)
|
@@ -24,7 +24,7 @@ shared_examples 'Customer API' do
|
|
24
24
|
expect(customer.default_source).to_not be_nil
|
25
25
|
expect(customer.default_source).to eq customer.sources.data.first.id
|
26
26
|
|
27
|
-
expect { customer.source }.to raise_error
|
27
|
+
expect { customer.source }.to raise_error(NoMethodError)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "creates a stripe customer with a default payment method" do
|
@@ -80,6 +80,10 @@ shared_examples 'SetupIntent API' do
|
|
80
80
|
|
81
81
|
updated = Stripe::SetupIntent.retrieve(original.id)
|
82
82
|
|
83
|
-
|
83
|
+
if StripeMock::Compat.stripe_gte_13?
|
84
|
+
expect(updated.metadata[:foo]).to eq("bar")
|
85
|
+
else
|
86
|
+
expect(updated.metadata[:foo]).to eq(:bar)
|
87
|
+
end
|
84
88
|
end
|
85
89
|
end
|
@@ -203,7 +203,7 @@ shared_examples 'Customer Subscriptions with plans' do
|
|
203
203
|
|
204
204
|
expect {
|
205
205
|
Stripe::Subscription.create(plan: plan.id, customer: customer.id, promotion_code: promotion_code.id)
|
206
|
-
}.not_to raise_error
|
206
|
+
}.not_to raise_error
|
207
207
|
end
|
208
208
|
|
209
209
|
it "does not permit both coupon and promotion code" do
|
@@ -98,10 +98,17 @@ shared_examples 'Transfer API' do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "cancels a stripe transfer" do
|
101
|
-
|
102
|
-
|
101
|
+
if StripeMock::Compat.stripe_gte_13?
|
102
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
103
|
+
res, api_key = Stripe::APIRequestor.active_requestor.execute_request(:post, "/v1/transfers/#{original.id}/cancel", :api)
|
103
104
|
|
104
|
-
|
105
|
+
expect(res.status).to eq("canceled")
|
106
|
+
else
|
107
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
108
|
+
res, api_key = Stripe::StripeClient.active_client.execute_request(:post, "/v1/transfers/#{original.id}/cancel", api_key: 'api_key')
|
109
|
+
|
110
|
+
expect(res.data[:status]).to eq("canceled")
|
111
|
+
end
|
105
112
|
end
|
106
113
|
|
107
114
|
it "cannot retrieve a transfer that doesn't exist" do
|
data/spec/spec_helper.rb
CHANGED
data/spec/stripe_mock_spec.rb
CHANGED
@@ -4,28 +4,50 @@ describe StripeMock do
|
|
4
4
|
|
5
5
|
it "overrides stripe's request method" do
|
6
6
|
StripeMock.start
|
7
|
-
|
7
|
+
if StripeMock::Compat.stripe_gte_13?
|
8
|
+
StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', :api, {}, {}, []) # no error
|
9
|
+
else
|
10
|
+
StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', api_key: 'abcde') # no error
|
11
|
+
end
|
8
12
|
StripeMock.stop
|
9
13
|
end
|
10
14
|
|
11
15
|
it "overrides stripe's execute_request method in other threads" do
|
12
16
|
StripeMock.start
|
13
|
-
|
17
|
+
if StripeMock::Compat.stripe_gte_13?
|
18
|
+
Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', :api, {}, {}, []) }.join # no error
|
19
|
+
else
|
20
|
+
Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method,:xtest, '/', api_key: 'abcde') }.join # no error
|
21
|
+
end
|
14
22
|
StripeMock.stop
|
15
23
|
end
|
16
24
|
|
17
25
|
it "reverts overriding stripe's request method" do
|
18
|
-
StripeMock.
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
if StripeMock::Compat.stripe_gte_13?
|
27
|
+
StripeMock.start
|
28
|
+
StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', :api, {}, {}, []) # no error
|
29
|
+
StripeMock.stop
|
30
|
+
expect { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :x, '/', :api, {}, {}, []) }.to raise_error Stripe::APIError
|
31
|
+
else
|
32
|
+
StripeMock.start
|
33
|
+
StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', api_key: 'abcde') # no error
|
34
|
+
StripeMock.stop
|
35
|
+
expect { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :x, '/', api_key: 'abcde') }.to raise_error Stripe::APIError
|
36
|
+
end
|
22
37
|
end
|
23
38
|
|
24
39
|
it "reverts overriding stripe's execute_request method in other threads" do
|
25
|
-
StripeMock.
|
26
|
-
|
27
|
-
|
28
|
-
|
40
|
+
if StripeMock::Compat.stripe_gte_13?
|
41
|
+
StripeMock.start
|
42
|
+
Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', :api, {}, {}, []) }.join # no error
|
43
|
+
StripeMock.stop
|
44
|
+
expect { Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :x, '/', :api, {}, {}, []) }.join }.to raise_error Stripe::APIError
|
45
|
+
else
|
46
|
+
StripeMock.start
|
47
|
+
Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :xtest, '/', api_key: 'abcde') }.join # no error
|
48
|
+
StripeMock.stop
|
49
|
+
expect { Thread.new { StripeMock::Compat.active_client.send(StripeMock::Compat.method, :x, '/', api_key: 'abcde') }.join }.to raise_error Stripe::APIError
|
50
|
+
end
|
29
51
|
end
|
30
52
|
|
31
53
|
it "does not persist data between mock sessions" do
|
@@ -79,11 +101,11 @@ describe StripeMock do
|
|
79
101
|
|
80
102
|
it "cannot be toggled when already started" do
|
81
103
|
StripeMock.start
|
82
|
-
expect { StripeMock.toggle_live(true) }.to raise_error
|
104
|
+
expect { StripeMock.toggle_live(true) }.to raise_error(RuntimeError, "You cannot toggle StripeMock live when it has already started.")
|
83
105
|
StripeMock.stop
|
84
106
|
|
85
107
|
StripeMock.instance_variable_set(:@state, 'remote')
|
86
|
-
expect { StripeMock.toggle_live(true) }.to raise_error
|
108
|
+
expect { StripeMock.toggle_live(true) }.to raise_error(RuntimeError, "You cannot toggle StripeMock live when it has already started.")
|
87
109
|
end
|
88
110
|
end
|
89
111
|
|
@@ -104,7 +126,7 @@ describe StripeMock do
|
|
104
126
|
end
|
105
127
|
|
106
128
|
it "throws an error on an unknown strategy" do
|
107
|
-
expect { StripeMock.create_test_helper(:lol) }.to raise_error
|
129
|
+
expect { StripeMock.create_test_helper(:lol) }.to raise_error(RuntimeError, "Invalid test helper strategy: :lol")
|
108
130
|
end
|
109
131
|
|
110
132
|
it "can configure the default strategy" do
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
23
|
gem.require_paths = ['lib']
|
24
24
|
|
25
|
-
gem.add_dependency 'stripe', '> 5', '<
|
25
|
+
gem.add_dependency 'stripe', '> 5', '< 14'
|
26
26
|
gem.add_dependency 'multi_json', '~> 1.0'
|
27
27
|
gem.add_dependency 'dante', '>= 0.2.0'
|
28
28
|
gem.add_dependency 'drb', '>= 2.0.4', '< 3'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
version: '5'
|
19
19
|
- - "<"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '14'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
version: '5'
|
29
29
|
- - "<"
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
31
|
+
version: '14'
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
33
|
name: multi_json
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,12 +116,18 @@ files:
|
|
116
116
|
- ".github/workflows/rspec_tests.yml"
|
117
117
|
- ".gitignore"
|
118
118
|
- ".rspec"
|
119
|
+
- Appraisals
|
119
120
|
- CHANGELOG.md
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
125
|
- bin/stripe-mock-server
|
126
|
+
- gemfiles/.bundle/config
|
127
|
+
- gemfiles/stripe_12.gemfile
|
128
|
+
- gemfiles/stripe_12.gemfile.lock
|
129
|
+
- gemfiles/stripe_13.gemfile
|
130
|
+
- gemfiles/stripe_13.gemfile.lock
|
125
131
|
- lib/stripe_mock.rb
|
126
132
|
- lib/stripe_mock/api/account_balance.rb
|
127
133
|
- lib/stripe_mock/api/bank_tokens.rb
|
@@ -137,6 +143,7 @@ files:
|
|
137
143
|
- lib/stripe_mock/api/test_helpers.rb
|
138
144
|
- lib/stripe_mock/api/webhooks.rb
|
139
145
|
- lib/stripe_mock/client.rb
|
146
|
+
- lib/stripe_mock/compat.rb
|
140
147
|
- lib/stripe_mock/data.rb
|
141
148
|
- lib/stripe_mock/data/list.rb
|
142
149
|
- lib/stripe_mock/error_queue.rb
|