rspec-stripe 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: d834cf81f82f022399af9efa0b4db2a19c1976bc
4
- data.tar.gz: 0472e3d0a23950e0eddc232cc6f2f03a5c4712af
3
+ metadata.gz: 05512b6ddcbfa7a5bb9f103342b47ba5a4fdd8e6
4
+ data.tar.gz: 2496b4b322b68869cdfeff2d1ec56c45f44d2e02
5
5
  SHA512:
6
- metadata.gz: 8b6a5a93d2b0d57a2d1def68f09e649b0b48bf121c5f49f349f416f86a7e3e62f5b0dbd71eaab9e38048ff3a88a3eed88d0d1e1455229a469f9dff8bcc70c66e
7
- data.tar.gz: 43b4b1f60e26c9e70f7a993b414c029b24b2a74096c4f25cd0ad665ba57e359cb8101c3bf383c40edcebd5503014cceecccc27a10fb1cce34bc9809bd15b5bf8
6
+ metadata.gz: 7e159ef49ad43beab92b085691c5030ed167a30df5b935e3846cc8ba1bec92077be56d0208c741642b8eefae9e1c437211f940bb21ca858fbc388752e81cbf80
7
+ data.tar.gz: 3b54f7060a6f98bb27e748c13e7fa41dcf688a7f1bda285ccb6a740aa986bbeb6892c31be59cc309769120f46609a0a51aa3ae3d7f37012872a6edee8ca837ff
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
  gem 'stripe', git: 'https://github.com/stripe/stripe-ruby'
6
6
  gem 'rspec', '~> 3.1'
7
7
  gem 'dotenv'
8
+ gem 'fakeweb'
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- rspec-stripe (0.0.1)
13
+ rspec-stripe (0.0.2)
14
14
 
15
15
  GEM
16
16
  remote: https://rubygems.org/
@@ -19,6 +19,7 @@ GEM
19
19
  dotenv (0.11.1)
20
20
  dotenv-deployment (~> 0.0.2)
21
21
  dotenv-deployment (0.0.2)
22
+ fakeweb (1.3.0)
22
23
  json (1.8.1)
23
24
  mime-types (2.3)
24
25
  netrc (0.7.7)
@@ -43,6 +44,7 @@ PLATFORMS
43
44
 
44
45
  DEPENDENCIES
45
46
  dotenv
47
+ fakeweb
46
48
  rspec (~> 3.1)
47
49
  rspec-stripe!
48
50
  stripe!
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ rspec-stripe [![Code Climate](https://codeclimate.com/github/sb8244/rspec-stripe/badges/gpa.svg)](https://codeclimate.com/github/sb8244/rspec-stripe) [![Gem Version](https://badge.fury.io/rb/rspec-stripe.svg)](http://badge.fury.io/rb/rspec-stripe)
2
+ ============
3
+
4
+ The goal of this project is to easily setup the stripe environment for your tests. In the past, you probably had to create a customer, then a plan, then assign the plan, then create your new plan. That is extremely cumbersome to do once and record. It becomes damn near impossible to recreate that cassette 6 months later when you're refreshing your specs.
5
+
6
+ With RSpec-Stripe, you can say what you want for your spec, and have it injected into the spec. Like this:
7
+
8
+ ```ruby
9
+ it "gives me a customer", stripe: { customer: :new } do
10
+ expect {
11
+ Stripe::Customer.retrieve(stripe_customer.id)
12
+ }.not_to raise_error
13
+
14
+ expect(stripe_plan).to eq(nil)
15
+ expect(stripe_subscription).to eq(nil)
16
+ end
17
+
18
+ it "gives a plan", stripe: { plan: "test" } do
19
+ expect(stripe_plan).not_to eq(nil)
20
+
21
+ expect(stripe_customer).to eq(nil)
22
+ expect(stripe_subscription).to eq(nil)
23
+ end
24
+
25
+ it "gives me a subscription", stripe: { customer: :new, plan: "test", subscription: "test" } do
26
+ expect(stripe_customer).not_to eq(nil)
27
+ expect(stripe_plan).not_to eq(nil)
28
+ expect(stripe_subscription).not_to eq(nil)
29
+ end
30
+ ```
31
+
32
+ After the spec, any newly created Stripe objects will be removed. However, if you specify an already existing Stripe object, it will not be removed after the spec.
33
+
34
+ Installation
35
+ ============
36
+
37
+ 1. Include `gem 'rspec-stripe'` in your Gemfile
38
+ 2. `bundle install`
39
+ 3. In your spec_helper.rb file, include `require 'rspec-stripe'` at the top.
40
+ 4. Bootstrap it for RSpec:
41
+
42
+ ```
43
+ RSpecStripe.configure do |config|
44
+ config.configure_rspec_metadata!
45
+ end
46
+ ```
@@ -9,12 +9,14 @@ module RSpecStripe::Factory
9
9
 
10
10
  def get
11
11
  @get ||= begin
12
- customer.cards.create(card: recipes[id].merge(
13
- exp_month: "01",
14
- exp_year: "2025",
15
- cvc: "111",
16
- name: customer.id
17
- ))
12
+ customer.cards.create(
13
+ card: {
14
+ exp_month: "01",
15
+ exp_year: "2025",
16
+ cvc: "111",
17
+ name: customer.id
18
+ }.merge(recipes[id])
19
+ )
18
20
  end
19
21
  end
20
22
 
@@ -26,6 +28,39 @@ module RSpecStripe::Factory
26
28
  {
27
29
  visa: {
28
30
  number: "4242424242424242"
31
+ },
32
+ mastercard: {
33
+ number: "5555555555554444"
34
+ },
35
+ amex: {
36
+ number: "378282246310005"
37
+ },
38
+ discover: {
39
+ number: "6011111111111117"
40
+ },
41
+ diners: {
42
+ number: "30569309025904"
43
+ },
44
+ jcb: {
45
+ number: "3530111333300000"
46
+ },
47
+ card_declined: {
48
+ number: "4000000000000002"
49
+ },
50
+ incorrect_number: {
51
+ number: "4242424242424241"
52
+ },
53
+ invalid_expiry_month: {
54
+ number: "4242424242424242",
55
+ exp_month: "13"
56
+ },
57
+ invalid_expiry_year: {
58
+ number: "4242424242424242",
59
+ exp_year: "1970"
60
+ },
61
+ invalid_cvc: {
62
+ number: "4242424242424242",
63
+ cvc: "99"
29
64
  }
30
65
  }
31
66
  end
@@ -2,7 +2,6 @@ module RSpecStripe::Factory
2
2
  Subscription = Struct.new(:id, :customer) do
3
3
  def get
4
4
  @get ||= begin
5
- cancel_subscriptions
6
5
  customer.subscriptions.create(plan: id)
7
6
  end
8
7
  end
@@ -10,13 +9,5 @@ module RSpecStripe::Factory
10
9
  def cleanup
11
10
  get.delete
12
11
  end
13
-
14
- private
15
-
16
- def cancel_subscriptions
17
- customer.subscriptions.all.each do |sub|
18
- sub.delete
19
- end
20
- end
21
12
  end
22
13
  end
@@ -38,10 +38,12 @@ module RSpecStripe
38
38
  end
39
39
 
40
40
  def subscription_factory
41
+ raise "No customer given" unless customer
41
42
  @subscription_factory ||= RSpecStripe::Factory::Subscription.new(recipes[:subscription], customer)
42
43
  end
43
44
 
44
45
  def card_factory
46
+ raise "No customer given" unless customer
45
47
  @card_factory ||= RSpecStripe::Factory::Card.new(recipes[:card], customer)
46
48
  end
47
49
  end
data/rspec-stripe.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.require_paths = ["lib"]
13
13
  s.files = `git ls-files`.split("\n")
14
14
 
15
- s.version = "0.0.2"
15
+ s.version = "0.0.3"
16
16
  s.required_ruby_version = '>= 2.0.0'
17
17
  s.required_rubygems_version = '>= 1.6.2'
18
18
  end
data/spec/basic_rspec.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- Stripe.api_key = ENV['STRIPE_TEST_KEY']
4
-
5
3
  describe 'Basic' do
6
4
  it "gives me a customer", stripe: { customer: :new } do
7
5
  expect {
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+ require 'fakeweb'
3
+
4
+ # Only calls that we stub out can work, giving confidence that our tests are only
5
+ # making the calls that we want
6
+ FakeWeb.allow_net_connect = false
7
+
8
+ describe RSpecStripe::Runner do
9
+ describe "customer" do
10
+ let(:customer_double) { double(Stripe::Customer) }
11
+
12
+ context "with a new customer" do
13
+ before(:each) {
14
+ expect(Stripe::Customer).to receive(:create).once { customer_double }
15
+ }
16
+
17
+ it "creates a customer" do
18
+ runner = RSpecStripe::Runner.new({customer: :new})
19
+ runner.call!
20
+ end
21
+
22
+ it "cleans up the customer" do
23
+ expect(customer_double).to receive(:delete).once
24
+ runner = RSpecStripe::Runner.new({customer: :new})
25
+ runner.call!
26
+ runner.cleanup!
27
+ end
28
+ end
29
+
30
+ context "with an existing customer" do
31
+ before(:each) {
32
+ expect(Stripe::Customer).to receive(:retrieve).once { customer_double }
33
+ }
34
+
35
+ it "doesn't create a customer" do
36
+ runner = RSpecStripe::Runner.new({customer: "id"})
37
+ runner.call!
38
+ end
39
+
40
+ it "doesn't clean up a customer" do
41
+ runner = RSpecStripe::Runner.new({customer: "id"})
42
+ runner.call!
43
+ runner.cleanup!
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "plan" do
49
+ let(:plan_double) { double(Stripe::Plan) }
50
+
51
+ context "with a new plan" do
52
+ before(:each) {
53
+ expect(Stripe::Plan).to receive(:retrieve).once { raise Stripe::InvalidRequestError.new("", "", 404) }
54
+ expect(Stripe::Plan).to receive(:create).once.with(hash_including(name: "Amazing Gold Plan")) { plan_double }
55
+ }
56
+
57
+ it "creates the plan" do
58
+ runner = RSpecStripe::Runner.new({plan: "test"})
59
+ runner.call!
60
+ end
61
+
62
+ it "cleans up" do
63
+ expect(plan_double).to receive(:delete).once
64
+ runner = RSpecStripe::Runner.new({plan: "test"})
65
+ runner.call!
66
+ runner.cleanup!
67
+ end
68
+
69
+ it "can create plans based on recipes"
70
+ end
71
+
72
+ context "with an existing plan" do
73
+ before(:each) {
74
+ expect(Stripe::Plan).to receive(:retrieve).once { plan_double }
75
+ }
76
+
77
+ it "retrieves the plan" do
78
+ runner = RSpecStripe::Runner.new({plan: "test"})
79
+ runner.call!
80
+ end
81
+
82
+ it "doesn't clean up" do
83
+ runner = RSpecStripe::Runner.new({plan: "test"})
84
+ runner.call!
85
+ runner.cleanup!
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "card" do
91
+ let(:card_double) { double(Stripe::Card) }
92
+ let(:customer_double) { double(Stripe::Customer, id: "id") }
93
+
94
+ context "without a customer" do
95
+ it "raises error" do
96
+ runner = RSpecStripe::Runner.new({card: :visa})
97
+ expect { runner.call! }.to raise_error("No customer given")
98
+ end
99
+ end
100
+
101
+ context "with a customer" do
102
+ before(:each) {
103
+ expect(Stripe::Customer).to receive(:retrieve).once { customer_double }
104
+ expect(customer_double).to receive(:cards).once {
105
+ stub = double("cards")
106
+ expect(stub).to receive(:create).once.with(card: hash_including(number: "4242424242424242")) { card_double }
107
+ stub
108
+ }
109
+ }
110
+
111
+ it "creates the card" do
112
+ runner = RSpecStripe::Runner.new({customer: "id", card: :visa})
113
+ runner.call!
114
+ end
115
+
116
+ it "cleans up" do
117
+ expect(card_double).to receive(:delete).once
118
+ runner = RSpecStripe::Runner.new({customer: "id", card: :visa})
119
+ runner.call!
120
+ runner.cleanup!
121
+ end
122
+
123
+ it "can create cards based on recipes"
124
+ end
125
+ end
126
+
127
+ describe "subscription" do
128
+ let(:card_double) { double(Stripe::Card) }
129
+
130
+ context "without a customer" do
131
+ it "raises error" do
132
+ runner = RSpecStripe::Runner.new({subscription: "test"})
133
+ expect { runner.call! }.to raise_error("No customer given")
134
+ end
135
+ end
136
+
137
+ context "with a customer" do
138
+ let(:customer_double) { double(Stripe::Customer, id: "id") }
139
+ before(:each) {
140
+ expect(Stripe::Customer).to receive(:retrieve).once { customer_double }
141
+ expect(customer_double).to receive(:subscriptions).once {
142
+ stub = double("subscriptions")
143
+ expect(stub).to receive(:create).once.with(plan: "test")
144
+ stub
145
+ }
146
+ expect(customer_double).to receive(:cards).once {
147
+ stub = double("cards")
148
+ expect(stub).to receive(:create).once.with(card: hash_including(number: card_number)) { card_double }
149
+ stub
150
+ }
151
+ }
152
+
153
+ context "without a card specified" do
154
+ let(:card_number) { "4242424242424242" }
155
+
156
+ it "creates a generic card and subscription" do
157
+ runner = RSpecStripe::Runner.new({customer: "id", subscription: "test"})
158
+ runner.call!
159
+ end
160
+ end
161
+
162
+ context "with a card specified" do
163
+ let(:card_number) { "5555555555554444" }
164
+
165
+ it "creates the specified card subscription" do
166
+ runner = RSpecStripe::Runner.new({customer: "id", subscription: "test", card: :mastercard})
167
+ runner.call!
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,8 @@ require 'rspec-stripe'
5
5
 
6
6
  Dotenv.load
7
7
 
8
+ Stripe.api_key = ENV['STRIPE_TEST_KEY']
9
+
8
10
  RSpecStripe.configure do |config|
9
11
  config.configure_rspec_metadata!
10
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Bussey
@@ -19,6 +19,7 @@ files:
19
19
  - ".gitignore"
20
20
  - Gemfile
21
21
  - Gemfile.lock
22
+ - README.md
22
23
  - lib/rspec-stripe.rb
23
24
  - lib/rspec-stripe/configuration.rb
24
25
  - lib/rspec-stripe/factories/card.rb
@@ -29,6 +30,7 @@ files:
29
30
  - lib/rspec-stripe/test_frameworks/rspec.rb
30
31
  - rspec-stripe.gemspec
31
32
  - spec/basic_rspec.rb
33
+ - spec/runner_spec.rb
32
34
  - spec/spec_helper.rb
33
35
  homepage: https://github.com/sb8244/rspec-stripe
34
36
  licenses: