stripe-ruby-mock 1.8.3.2 → 1.8.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/stripe_mock.rb CHANGED
@@ -3,6 +3,9 @@ require 'ostruct'
3
3
  require 'stripe_mock/version'
4
4
  require 'stripe_mock/data'
5
5
 
6
+ require 'stripe_mock/errors/stripe_mock_error'
7
+ require 'stripe_mock/errors/uninitialized_instance_error'
8
+
6
9
  require 'stripe_mock/api/instance'
7
10
  require 'stripe_mock/api/errors'
8
11
 
@@ -1,13 +1,14 @@
1
1
  module StripeMock
2
2
 
3
3
  def self.prepare_error(stripe_error)
4
+ raise UninitializedInstanceError if instance.nil?
4
5
  instance.pending_error = stripe_error
5
6
  end
6
7
 
7
8
  def self.prepare_card_error(code)
8
- return if instance.nil?
9
9
  args = card_error_args[code]
10
- instance.pending_error = Stripe::CardError.new(*args)
10
+ raise StripeMockError.new("Unrecognized stripe card error code: #{code}") if args.nil?
11
+ self.prepare_error Stripe::CardError.new(*args)
11
12
  end
12
13
 
13
14
  private
@@ -74,7 +74,7 @@ module StripeMock
74
74
  address_line1_check: nil,
75
75
  address_zip_check: nil
76
76
  },
77
- captured: false,
77
+ captured: params.has_key?(:capture) ? params[:capture] : true,
78
78
  failure_message: nil,
79
79
  amount_refunded: 0,
80
80
  customer: nil,
@@ -0,0 +1,15 @@
1
+ module StripeMock
2
+ class StripeMockError < StandardError
3
+
4
+ attr_reader :message
5
+
6
+ def initialize(message)
7
+ @message = message
8
+ end
9
+
10
+ def to_s
11
+ @message
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module StripeMock
2
+ class UninitializedInstanceError < StripeMockError
3
+
4
+ def initialize
5
+ super("StripeMock instance is nil (did you forget to call `StripeMock.start`?)")
6
+ end
7
+
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.8.3.2"
3
+ VERSION = "1.8.3.3"
4
4
  end
@@ -50,7 +50,6 @@ describe 'Charge API' do
50
50
  expect(charge.amount).to eq(original.amount)
51
51
  end
52
52
 
53
-
54
53
  it "retrieves a stripe charge with an id that doesn't exist" do
55
54
  charge = Stripe::Charge.retrieve('test_charge_x')
56
55
  expect(charge.id).to eq('test_charge_x')
@@ -58,4 +57,38 @@ describe 'Charge API' do
58
57
  expect(charge.card).to_not be_nil
59
58
  end
60
59
 
60
+ describe 'captured status value' do
61
+ it "reports captured by default" do
62
+ charge = Stripe::Charge.create({
63
+ amount: 777,
64
+ currency: 'USD',
65
+ card: 'card_token_abc'
66
+ })
67
+
68
+ expect(charge.captured).to be_true
69
+ end
70
+
71
+ it "reports captured if capture requested" do
72
+ charge = Stripe::Charge.create({
73
+ amount: 777,
74
+ currency: 'USD',
75
+ card: 'card_token_abc',
76
+ capture: true
77
+ })
78
+
79
+ expect(charge.captured).to be_true
80
+ end
81
+
82
+ it "reports not captured if capture: false requested" do
83
+ charge = Stripe::Charge.create({
84
+ amount: 777,
85
+ currency: 'USD',
86
+ card: 'card_token_abc',
87
+ capture: false
88
+ })
89
+
90
+ expect(charge.captured).to be_false
91
+ end
92
+ end
93
+
61
94
  end
@@ -69,6 +69,12 @@ describe 'Stripe Error Mocking' do
69
69
  # Card Error Helper Methods
70
70
  # # # # # # # # # # # # # #
71
71
 
72
+ it "raises an error for an unrecognized card error code" do
73
+ expect { StripeMock.prepare_card_error(:non_existant_error_code) }.to raise_error {|e|
74
+ expect(e).to be_a(StripeMock::StripeMockError)
75
+ }
76
+ end
77
+
72
78
  it "mocks an incorrect number card error" do
73
79
  StripeMock.prepare_card_error(:incorrect_number)
74
80
  expect_card_error 'incorrect_number', 'number'
@@ -27,4 +27,14 @@ describe StripeMock do
27
27
  StripeMock.stop
28
28
  end
29
29
 
30
+ it "throws an error when trying to prepare an error before starting" do
31
+ expect { StripeMock.prepare_error(StandardError.new) }.to raise_error {|e|
32
+ expect(e).to be_a(StripeMock::UninitializedInstanceError)
33
+ }
34
+
35
+ expect { StripeMock.prepare_card_error(:card_declined) }.to raise_error {|e|
36
+ expect(e).to be_a(StripeMock::UninitializedInstanceError)
37
+ }
38
+ end
39
+
30
40
  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.2
4
+ version: 1.8.3.3
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-05-30 00:00:00.000000000 Z
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -75,6 +75,8 @@ files:
75
75
  - lib/stripe_mock/api/errors.rb
76
76
  - lib/stripe_mock/api/instance.rb
77
77
  - lib/stripe_mock/data.rb
78
+ - lib/stripe_mock/errors/stripe_mock_error.rb
79
+ - lib/stripe_mock/errors/uninitialized_instance_error.rb
78
80
  - lib/stripe_mock/instance.rb
79
81
  - lib/stripe_mock/request_handlers/charges.rb
80
82
  - lib/stripe_mock/request_handlers/customers.rb