stripe-ruby-mock 1.8.3.5 → 1.8.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stripe_mock/api/client.rb +4 -0
- data/lib/stripe_mock/api/errors.rb +7 -2
- data/lib/stripe_mock/client.rb +6 -1
- data/lib/stripe_mock/errors/unstarted_state_error.rb +9 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock.rb +1 -0
- data/spec/instance_spec.rb +5 -0
- data/spec/server_spec.rb +7 -2
- data/spec/{stripe/charge_spec.rb → shared_stripe_examples/charges.rb} +2 -5
- data/spec/{stripe/customer_spec.rb → shared_stripe_examples/customers.rb} +2 -5
- data/spec/{stripe/error_mock_spec.rb → shared_stripe_examples/error_mocks.rb} +1 -4
- data/spec/{stripe/invoice_item_spec.rb → shared_stripe_examples/invoice_items.rb} +1 -4
- data/spec/{stripe/plan_spec.rb → shared_stripe_examples/plans.rb} +2 -5
- data/spec/spec_helper.rb +4 -0
- data/spec/stripe_mock_spec.rb +2 -2
- data/spec/support/stripe_examples.rb +16 -0
- metadata +15 -14
- data/spec/support/server_daemon.rb +0 -0
@@ -25,6 +25,10 @@ module StripeMock
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def self.redirect_to_mock_server(method, url, api_key, params={}, headers={})
|
28
|
+
if @remote_state_pending_error
|
29
|
+
raise @remote_state_pending_error
|
30
|
+
@remote_state_pending_error = nil
|
31
|
+
end
|
28
32
|
Stripe::Util.symbolize_names @client.mock_request(method, url, api_key, params, headers)
|
29
33
|
end
|
30
34
|
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module StripeMock
|
2
2
|
|
3
3
|
def self.prepare_error(stripe_error)
|
4
|
-
|
5
|
-
|
4
|
+
if @state == 'local'
|
5
|
+
instance.pending_error = stripe_error
|
6
|
+
elsif @state == 'remote'
|
7
|
+
@remote_state_pending_error = stripe_error
|
8
|
+
else
|
9
|
+
raise UnstartedStateError
|
10
|
+
end
|
6
11
|
end
|
7
12
|
|
8
13
|
def self.prepare_card_error(code)
|
data/lib/stripe_mock/client.rb
CHANGED
@@ -16,7 +16,12 @@ module StripeMock
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get_server_data(key)
|
19
|
-
timeout_wrap {
|
19
|
+
timeout_wrap {
|
20
|
+
# Massage the data make this behave the same as the local StripeMock.start
|
21
|
+
result = {}
|
22
|
+
@pipe.get_data(key).each {|k,v| result[k] = Stripe::Util.symbolize_names(v) }
|
23
|
+
result
|
24
|
+
}
|
20
25
|
end
|
21
26
|
|
22
27
|
def set_server_debug(toggle)
|
data/lib/stripe_mock/version.rb
CHANGED
data/lib/stripe_mock.rb
CHANGED
@@ -9,6 +9,7 @@ require 'stripe_mock/data'
|
|
9
9
|
|
10
10
|
require 'stripe_mock/errors/stripe_mock_error'
|
11
11
|
require 'stripe_mock/errors/uninitialized_instance_error'
|
12
|
+
require 'stripe_mock/errors/unstarted_state_error'
|
12
13
|
require 'stripe_mock/errors/server_timeout_error'
|
13
14
|
require 'stripe_mock/errors/closed_client_connection_error'
|
14
15
|
|
data/spec/instance_spec.rb
CHANGED
data/spec/server_spec.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require_stripe_examples
|
2
3
|
|
3
4
|
describe 'StripeMock Server' do
|
4
5
|
|
6
|
+
it_behaves_like_stripe do
|
7
|
+
def test_data_source(type); StripeMock.client.get_server_data(type); end
|
8
|
+
end
|
9
|
+
|
5
10
|
before(:all) do
|
6
11
|
StripeMock.spawn_server
|
7
12
|
end
|
@@ -37,14 +42,14 @@ describe 'StripeMock Server' do
|
|
37
42
|
|
38
43
|
server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
|
39
44
|
expect(server_customer_data).to_not be_nil
|
40
|
-
expect(server_customer_data[
|
45
|
+
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
41
46
|
|
42
47
|
StripeMock.stop_client
|
43
48
|
StripeMock.start_client
|
44
49
|
|
45
50
|
server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
|
46
51
|
expect(server_customer_data).to_not be_nil
|
47
|
-
expect(server_customer_data[
|
52
|
+
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
48
53
|
end
|
49
54
|
|
50
55
|
|
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
before { StripeMock.start }
|
6
|
-
after { StripeMock.stop }
|
3
|
+
shared_examples 'Charge API' do
|
7
4
|
|
8
5
|
it "creates a stripe charge item with a card token" do
|
9
6
|
charge = Stripe::Charge.create(
|
@@ -30,7 +27,7 @@ describe 'Charge API' do
|
|
30
27
|
currency: 'USD',
|
31
28
|
card: 'card_token_777'
|
32
29
|
})
|
33
|
-
data =
|
30
|
+
data = test_data_source(:charges)
|
34
31
|
expect(data[charge.id]).to_not be_nil
|
35
32
|
expect(data[charge.id][:amount]).to eq(333)
|
36
33
|
|
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
before { StripeMock.start }
|
6
|
-
after { StripeMock.stop }
|
3
|
+
shared_examples 'Customer API' do
|
7
4
|
|
8
5
|
it "creates a stripe customer" do
|
9
6
|
customer = Stripe::Customer.create({
|
@@ -25,7 +22,7 @@ describe 'Customer API' do
|
|
25
22
|
email: 'bob@bobbers.com',
|
26
23
|
card: 'another_card_token'
|
27
24
|
})
|
28
|
-
data =
|
25
|
+
data = test_data_source(:customers)
|
29
26
|
expect(data[customer.id]).to_not be_nil
|
30
27
|
expect(data[customer.id][:email]).to eq('johnny@appleseed.com')
|
31
28
|
|
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
before { StripeMock.start }
|
6
|
-
after { StripeMock.stop }
|
3
|
+
shared_examples 'Plan API' do
|
7
4
|
|
8
5
|
it "creates a stripe plan" do
|
9
6
|
plan = Stripe::Plan.create(
|
@@ -40,7 +37,7 @@ describe 'Plan API' do
|
|
40
37
|
:currency => 'USD',
|
41
38
|
:interval => 1
|
42
39
|
)
|
43
|
-
data =
|
40
|
+
data = test_data_source(:plans)
|
44
41
|
expect(data[plan.id]).to_not be_nil
|
45
42
|
expect(data[plan.id][:amount]).to eq(1100)
|
46
43
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/stripe_mock_spec.rb
CHANGED
@@ -29,11 +29,11 @@ describe StripeMock do
|
|
29
29
|
|
30
30
|
it "throws an error when trying to prepare an error before starting" do
|
31
31
|
expect { StripeMock.prepare_error(StandardError.new) }.to raise_error {|e|
|
32
|
-
expect(e).to be_a(StripeMock::
|
32
|
+
expect(e).to be_a(StripeMock::UnstartedStateError)
|
33
33
|
}
|
34
34
|
|
35
35
|
expect { StripeMock.prepare_card_error(:card_declined) }.to raise_error {|e|
|
36
|
-
expect(e).to be_a(StripeMock::
|
36
|
+
expect(e).to be_a(StripeMock::UnstartedStateError)
|
37
37
|
}
|
38
38
|
end
|
39
39
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
def require_stripe_examples
|
3
|
+
require 'shared_stripe_examples/charges'
|
4
|
+
require 'shared_stripe_examples/customers'
|
5
|
+
require 'shared_stripe_examples/error_mocks'
|
6
|
+
require 'shared_stripe_examples/invoice_items'
|
7
|
+
require 'shared_stripe_examples/plans'
|
8
|
+
end
|
9
|
+
|
10
|
+
def it_behaves_like_stripe(&block)
|
11
|
+
it_behaves_like 'Charge API', &block
|
12
|
+
it_behaves_like 'Customer API', &block
|
13
|
+
it_behaves_like 'Invoice Item API', &block
|
14
|
+
it_behaves_like 'Plan API', &block
|
15
|
+
it_behaves_like 'Stripe Error Mocking', &block
|
16
|
+
end
|
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: 1.8.3.
|
4
|
+
version: 1.8.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stripe
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/stripe_mock/errors/server_timeout_error.rb
|
117
117
|
- lib/stripe_mock/errors/stripe_mock_error.rb
|
118
118
|
- lib/stripe_mock/errors/uninitialized_instance_error.rb
|
119
|
+
- lib/stripe_mock/errors/unstarted_state_error.rb
|
119
120
|
- lib/stripe_mock/instance.rb
|
120
121
|
- lib/stripe_mock/request_handlers/charges.rb
|
121
122
|
- lib/stripe_mock/request_handlers/customers.rb
|
@@ -127,14 +128,14 @@ files:
|
|
127
128
|
- spec/instance_spec.rb
|
128
129
|
- spec/readme_spec.rb
|
129
130
|
- spec/server_spec.rb
|
131
|
+
- spec/shared_stripe_examples/charges.rb
|
132
|
+
- spec/shared_stripe_examples/customers.rb
|
133
|
+
- spec/shared_stripe_examples/error_mocks.rb
|
134
|
+
- spec/shared_stripe_examples/invoice_items.rb
|
135
|
+
- spec/shared_stripe_examples/plans.rb
|
130
136
|
- spec/spec_helper.rb
|
131
|
-
- spec/stripe/charge_spec.rb
|
132
|
-
- spec/stripe/customer_spec.rb
|
133
|
-
- spec/stripe/error_mock_spec.rb
|
134
|
-
- spec/stripe/invoice_item_spec.rb
|
135
|
-
- spec/stripe/plan_spec.rb
|
136
137
|
- spec/stripe_mock_spec.rb
|
137
|
-
- spec/support/
|
138
|
+
- spec/support/stripe_examples.rb
|
138
139
|
- stripe-ruby-mock.gemspec
|
139
140
|
homepage: https://github.com/mindeavor/stripe-ruby-mock
|
140
141
|
licenses:
|
@@ -165,11 +166,11 @@ test_files:
|
|
165
166
|
- spec/instance_spec.rb
|
166
167
|
- spec/readme_spec.rb
|
167
168
|
- spec/server_spec.rb
|
169
|
+
- spec/shared_stripe_examples/charges.rb
|
170
|
+
- spec/shared_stripe_examples/customers.rb
|
171
|
+
- spec/shared_stripe_examples/error_mocks.rb
|
172
|
+
- spec/shared_stripe_examples/invoice_items.rb
|
173
|
+
- spec/shared_stripe_examples/plans.rb
|
168
174
|
- spec/spec_helper.rb
|
169
|
-
- spec/stripe/charge_spec.rb
|
170
|
-
- spec/stripe/customer_spec.rb
|
171
|
-
- spec/stripe/error_mock_spec.rb
|
172
|
-
- spec/stripe/invoice_item_spec.rb
|
173
|
-
- spec/stripe/plan_spec.rb
|
174
175
|
- spec/stripe_mock_spec.rb
|
175
|
-
- spec/support/
|
176
|
+
- spec/support/stripe_examples.rb
|
File without changes
|