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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 148628f00d214cfaa405f65529b1b8155da9475063166370b0b287084afcd0d4
4
- data.tar.gz: ac5f7249f7a83d1fe2ac9f7a1eb4ff007465b404289f1f8bd60d277fe110d4d9
3
+ metadata.gz: 25863512f9198c5d281a21813ce21357d94d9cb39a346a65006135ba3baafd7d
4
+ data.tar.gz: 718a79b250972169ba5fa7f4c6c766cfee25038b1b730cb39758086a0f40c557
5
5
  SHA512:
6
- metadata.gz: 8627e73ab695f6a0403d8438abb979a3b4b241d1b04419a2e82844225426dbd19a02eef3ac95a719f644ece575090e46f68b504ab83d5a865e46d1e14f353099
7
- data.tar.gz: 9ea4b6e5b061a0d8342f4459fd558df25df4888bf713142e21263e73029411e6f226baa86eb6341de726891cb4245a34ef0c0d744e21b378d6afe0dcae64eda8
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: [ "master" ]
12
+ branches: ["master"]
13
13
  pull_request:
14
- branches: [ "master" ]
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: ['3.1', '3.2', '3.3']
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
- - uses: actions/checkout@v4
27
- - name: Install Ruby and gems
28
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
30
- uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: ${{ matrix.ruby }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Run tests
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
@@ -0,0 +1,7 @@
1
+ appraise "stripe-13" do
2
+ gem "stripe", "13.4.0"
3
+ end
4
+
5
+ appraise "stripe-12" do
6
+ gem "stripe", "12.6.0"
7
+ end
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
@@ -6,3 +6,5 @@ group :test do
6
6
  end
7
7
 
8
8
  gemspec
9
+
10
+ gem 'appraisal'
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 >= 2.7.0
33
- * stripe > 5 & < 11
34
+ * ruby >= 3.0.0
35
+ * stripe > 5 & <= 13
34
36
 
35
37
  ### Specifications
36
38
 
37
- **STRIPE API TARGET VERSION:** 2019-08-20 (master) - we try, but some features are not implemented yet.
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,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "stripe", "12.6.0"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "dotenv"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -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,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "stripe", "13.4.0"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "dotenv"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -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
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| StripeMock.redirect_to_mock_server(*args, **keyword_args) }
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(method, url, api_key: nil, api_base: nil, usage: [], params: {}, headers: {})
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(method, url, api_key: api_key, params: params, headers: headers)
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 = Stripe::StripeClient.instance_method(:execute_request)
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
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| instance.mock_request(*args, **keyword_args) }
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
- Stripe::StripeClient.send(:define_method, :execute_request, @original_execute_request_method)
34
+ Compat.client.send(:define_method, Compat.method, @original_execute_request_method)
33
35
  end
34
36
 
35
37
  def self.instance; @instance; end
@@ -13,9 +13,9 @@ module StripeMock
13
13
  @state = 'ready'
14
14
  end
15
15
 
16
- def mock_request(method, url, api_key: nil, params: {}, headers: {})
16
+ def mock_request(*args, **kwargs)
17
17
  timeout_wrap do
18
- @pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
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
@@ -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: [
@@ -111,7 +111,23 @@ module StripeMock
111
111
  @base_strategy = TestStrategies::Base.new
112
112
  end
113
113
 
114
- def mock_request(method, url, api_key: nil, api_base: nil, usage: [], params: {}, headers: {})
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
- [to_faraday_hash(res), api_key]
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
- [{}, api_key]
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
@@ -3,6 +3,7 @@ module StripeMock
3
3
  module Helpers
4
4
  def add_coupon_to_object(object, coupon)
5
5
  discount_attrs = {}.tap do |attrs|
6
+ attrs[:object] = "discount"
6
7
  attrs[object[:object]] = object[:id]
7
8
  attrs[:coupon] = coupon
8
9
  attrs[:start] = Time.now.to_i
@@ -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
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "4.1.0"
3
+ VERSION = "5.0.0"
4
4
  end
data/lib/stripe_mock.rb CHANGED
@@ -8,7 +8,7 @@ require 'stripe'
8
8
  require 'stripe_mock/version'
9
9
  require 'stripe_mock/util'
10
10
  require 'stripe_mock/error_queue'
11
-
11
+ require 'stripe_mock/compat'
12
12
  require 'stripe_mock/data'
13
13
  require 'stripe_mock/data/list'
14
14
 
@@ -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
- expect(res.data[:name]).to eq('Symbol Product')
24
- expect(res.data[:type]).to eq('service')
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
- stripe_helper.create_plan(id: 'x', product: product.id)
58
- response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
59
- response.data.keys.each {|k| expect(k).to be_a(Symbol) }
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)
@@ -55,7 +55,7 @@ shared_examples 'Account API' do
55
55
  account.tos_acceptance.date = nil
56
56
  expect {
57
57
  account.save
58
- }.to raise_error
58
+ }.to raise_error(Stripe::InvalidRequestError, /Invalid integer/)
59
59
  end
60
60
 
61
61
  context 'with tos acceptance date' do
@@ -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
- expect(updated.metadata[:foo]).to eq(:bar)
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(Stripe::InvalidRequestError)
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
- original = Stripe::Transfer.create(amount: "100", currency: "usd")
102
- res, api_key = Stripe::StripeClient.active_client.execute_request(:post, "/v1/transfers/#{original.id}/cancel", api_key: 'api_key')
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
- expect(res.data[:status]).to eq("canceled")
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
@@ -5,6 +5,7 @@ require 'rspec'
5
5
  require 'stripe'
6
6
  require 'stripe_mock'
7
7
  require 'stripe_mock/server'
8
+ require 'stripe_mock/compat'
8
9
  require 'dotenv'
9
10
 
10
11
  Dotenv.load('.env')
@@ -4,28 +4,50 @@ describe StripeMock do
4
4
 
5
5
  it "overrides stripe's request method" do
6
6
  StripeMock.start
7
- Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
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
- Thread.new { Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') }.join # no error
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.start
19
- Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
20
- StripeMock.stop
21
- expect { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.to raise_error Stripe::APIError
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.start
26
- Thread.new { Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') }.join # no error
27
- StripeMock.stop
28
- expect { Thread.new { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.join }.to raise_error Stripe::APIError
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
@@ -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', '< 13'
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.1.0
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: '13'
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: '13'
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