Skip to content
This repository
Browse code

Split up specs.

  • Loading branch information...
commit cc7463f7070b740706f1d36edf81df749cdb08fb 1 parent 313d8fd
Gabe Berke-Williams authored November 03, 2011
32  spec/fake_braintree/credit_card_spec.rb
... ...
@@ -0,0 +1,32 @@
  1
+require 'spec_helper'
  2
+
  3
+describe FakeBraintree::SinatraApp do
  4
+  context "Braintree::CreditCard.find" do
  5
+    let(:cc_number)         { %w(4111 1111 1111 9876).join }
  6
+    let(:expiration_date)   { "04/2016" }
  7
+    let(:token)             { braintree_credit_card_token(cc_number, expiration_date) }
  8
+
  9
+    it "gets the correct credit card" do
  10
+      credit_card = Braintree::CreditCard.find(token)
  11
+
  12
+      credit_card.last_4.should == "9876"
  13
+      credit_card.expiration_year.should == "2016"
  14
+      credit_card.expiration_month.should == "04"
  15
+    end
  16
+  end
  17
+
  18
+  context "Braintree::CreditCard.sale" do
  19
+    let(:cc_number)         { %w(4111 1111 1111 9876).join }
  20
+    let(:expiration_date)   { "04/2016" }
  21
+    let(:token)             { braintree_credit_card_token(cc_number, expiration_date) }
  22
+    let(:amount)            { 10.00 }
  23
+
  24
+    it "successfully creates a sale" do
  25
+      result = Braintree::CreditCard.sale(token, amount: amount, options: {submit_for_settlement: true})
  26
+      result.should be_success
  27
+
  28
+      Braintree::Transaction.find(result.transaction.id).should be
  29
+      lambda { Braintree::Transaction.find("foo") }.should raise_error(Braintree::NotFoundError)
  30
+    end
  31
+  end
  32
+end
51  spec/fake_braintree/customer_spec.rb
... ...
@@ -0,0 +1,51 @@
  1
+require 'spec_helper'
  2
+
  3
+describe FakeBraintree::SinatraApp do
  4
+  context "Braintree::Customer.create" do
  5
+    let(:cc_number)       { %w(4111 1111 1111 1111).join }
  6
+    let(:expiration_date) { "04/2016" }
  7
+    after { FakeBraintree.verify_all_cards = false }
  8
+
  9
+    it "successfully creates a customer" do
  10
+      result = Braintree::Customer.create(
  11
+        :credit_card => {
  12
+          :number          => cc_number,
  13
+          :expiration_date => expiration_date
  14
+        })
  15
+
  16
+      result.should be_success
  17
+    end
  18
+
  19
+    it "verifies the card number when passed :verify_card => true" do
  20
+      Braintree::Customer.create(
  21
+        :credit_card => {
  22
+          :number          => cc_number,
  23
+          :expiration_date => expiration_date,
  24
+          :options         => { :verify_card => true }
  25
+        }).should be_success
  26
+
  27
+      Braintree::Customer.create(
  28
+        :credit_card => {
  29
+          :number          => '123456',
  30
+          :expiration_date => expiration_date,
  31
+          :options         => { :verify_card => true }
  32
+        }).should_not be_success
  33
+    end
  34
+
  35
+    it "verifies the card number when FakeBraintree.verify_all_cards == true" do
  36
+      FakeBraintree.verify_all_cards!
  37
+
  38
+      Braintree::Customer.create(
  39
+        :credit_card => {
  40
+          :number          => cc_number,
  41
+          :expiration_date => expiration_date
  42
+        }).should be_success
  43
+
  44
+      Braintree::Customer.create(
  45
+        :credit_card => {
  46
+          :number          => '123456',
  47
+          :expiration_date => expiration_date
  48
+        }).should_not be_success
  49
+    end
  50
+  end
  51
+end
126  spec/fake_braintree/sinatra_app_spec.rb
... ...
@@ -1,126 +0,0 @@
1  
-require 'spec_helper'
2  
-
3  
-module FakeBraintree
4  
-  describe SinatraApp, "Braintree::CreditCard.find" do
5  
-    let(:cc_number)         { %w(4111 1111 1111 9876).join }
6  
-    let(:expiration_date)   { "04/2016" }
7  
-    let(:token)             { braintree_credit_card_token(cc_number, expiration_date) }
8  
-
9  
-    it "gets the correct credit card" do
10  
-      credit_card = Braintree::CreditCard.find(token)
11  
-
12  
-      credit_card.last_4.should == "9876"
13  
-      credit_card.expiration_year.should == "2016"
14  
-      credit_card.expiration_month.should == "04"
15  
-    end
16  
-  end
17  
-
18  
-  describe SinatraApp, "Braintree::CreditCard.sale" do
19  
-    let(:cc_number)         { %w(4111 1111 1111 9876).join }
20  
-    let(:expiration_date)   { "04/2016" }
21  
-    let(:token)             { braintree_credit_card_token(cc_number, expiration_date) }
22  
-    let(:amount)            { 10.00 }
23  
-
24  
-    it "successfully creates a sale" do
25  
-      result = Braintree::CreditCard.sale(token, amount: amount, options: {submit_for_settlement: true})
26  
-      result.should be_success
27  
-
28  
-      Braintree::Transaction.find(result.transaction.id).should be
29  
-      lambda { Braintree::Transaction.find("foo") }.should raise_error(Braintree::NotFoundError)
30  
-    end
31  
-  end
32  
-
33  
-  describe SinatraApp, "Braintree::Subscription.create" do
34  
-    let(:plan_id)                { 'plan-id-from-braintree-control-panel' }
35  
-    let(:cc_number)              { %w(4111 1111 1111 9876).join }
36  
-    let(:expiration_date)        { "04/2016" }
37  
-    let(:payment_method_token)   { braintree_credit_card_token(cc_number, expiration_date) }
38  
-    let(:payment_method_token_2) { braintree_credit_card_token(cc_number.sub('1', '5'), expiration_date) }
39  
-
40  
-    it "successfully creates a subscription" do
41  
-      result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
42  
-                                              :plan_id => plan_id)
43  
-      result.should be_success
44  
-    end
45  
-
46  
-    it "assigns a Braintree-esque ID to the subscription" do
47  
-      result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
48  
-                                              :plan_id => plan_id)
49  
-
50  
-      result.subscription.id.should =~ /^[a-z0-9]{6}$/
51  
-    end
52  
-
53  
-    it "assigns unique IDs to each subscription" do
54  
-      first_result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
55  
-                                                    :plan_id => plan_id)
56  
-      second_result = Braintree::Subscription.create(:payment_method_token => payment_method_token_2,
57  
-                                                     :plan_id => plan_id)
58  
-
59  
-      first_result.subscription.id.should_not == second_result.subscription.id
60  
-    end
61  
-  end
62  
-
63  
-  describe SinatraApp, "Braintree::Subscription.find" do
64  
-    let(:cc_number)            { %w(4111 1111 1111 9876).join }
65  
-    let(:expiration_date)      { "04/2016" }
66  
-    let(:payment_method_token) { braintree_credit_card_token(cc_number, expiration_date) }
67  
-    let(:subscription_result)  { Braintree::Subscription.create(:payment_method_token => payment_method_token,
68  
-                                                                :plan_id => 'my-plan-id') }
69  
-
70  
-    it "can find a created subscription" do
71  
-      Braintree::Subscription.find(subscription_result.subscription.id).should be
72  
-    end
73  
-
74  
-    it "raises a Braintree:NotFoundError when it cannot find a subscription" do
75  
-      expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/)
76  
-    end
77  
-  end
78  
-
79  
-  describe SinatraApp, "Braintree::Customer.create" do
80  
-    let(:cc_number)       { %w(4111 1111 1111 1111).join }
81  
-    let(:expiration_date) { "04/2016" }
82  
-    after { FakeBraintree.verify_all_cards = false }
83  
-
84  
-    it "successfully creates a customer" do
85  
-      result = Braintree::Customer.create(
86  
-        :credit_card => {
87  
-          :number          => cc_number,
88  
-          :expiration_date => expiration_date
89  
-        })
90  
-
91  
-      result.should be_success
92  
-    end
93  
-
94  
-    it "verifies the card number when passed :verify_card => true" do
95  
-      Braintree::Customer.create(
96  
-        :credit_card => {
97  
-          :number          => cc_number,
98  
-          :expiration_date => expiration_date,
99  
-          :options         => { :verify_card => true }
100  
-        }).should be_success
101  
-
102  
-      Braintree::Customer.create(
103  
-        :credit_card => {
104  
-          :number          => '123456',
105  
-          :expiration_date => expiration_date,
106  
-          :options         => { :verify_card => true }
107  
-        }).should_not be_success
108  
-    end
109  
-
110  
-    it "verifies the card number when FakeBraintree.verify_all_cards == true" do
111  
-      FakeBraintree.verify_all_cards!
112  
-
113  
-      Braintree::Customer.create(
114  
-        :credit_card => {
115  
-          :number          => cc_number,
116  
-          :expiration_date => expiration_date
117  
-        }).should be_success
118  
-
119  
-      Braintree::Customer.create(
120  
-        :credit_card => {
121  
-          :number          => '123456',
122  
-          :expiration_date => expiration_date
123  
-        }).should_not be_success
124  
-    end
125  
-  end
126  
-end
49  spec/fake_braintree/subscription_spec.rb
... ...
@@ -0,0 +1,49 @@
  1
+require 'spec_helper'
  2
+
  3
+describe FakeBraintree::SinatraApp do
  4
+  context "Braintree::Subscription.create" do
  5
+    let(:plan_id)                { 'plan-id-from-braintree-control-panel' }
  6
+    let(:cc_number)              { %w(4111 1111 1111 9876).join }
  7
+    let(:expiration_date)        { "04/2016" }
  8
+    let(:payment_method_token)   { braintree_credit_card_token(cc_number, expiration_date) }
  9
+    let(:payment_method_token_2) { braintree_credit_card_token(cc_number.sub('1', '5'), expiration_date) }
  10
+
  11
+    it "successfully creates a subscription" do
  12
+      result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
  13
+                                              :plan_id => plan_id)
  14
+      result.should be_success
  15
+    end
  16
+
  17
+    it "assigns a Braintree-esque ID to the subscription" do
  18
+      result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
  19
+                                              :plan_id => plan_id)
  20
+
  21
+      result.subscription.id.should =~ /^[a-z0-9]{6}$/
  22
+    end
  23
+
  24
+    it "assigns unique IDs to each subscription" do
  25
+      first_result = Braintree::Subscription.create(:payment_method_token => payment_method_token,
  26
+                                                    :plan_id => plan_id)
  27
+      second_result = Braintree::Subscription.create(:payment_method_token => payment_method_token_2,
  28
+                                                     :plan_id => plan_id)
  29
+
  30
+      first_result.subscription.id.should_not == second_result.subscription.id
  31
+    end
  32
+  end
  33
+
  34
+  context "Braintree::Subscription.find" do
  35
+    let(:cc_number)            { %w(4111 1111 1111 9876).join }
  36
+    let(:expiration_date)      { "04/2016" }
  37
+    let(:payment_method_token) { braintree_credit_card_token(cc_number, expiration_date) }
  38
+    let(:subscription_result)  { Braintree::Subscription.create(:payment_method_token => payment_method_token,
  39
+                                                                :plan_id => 'my-plan-id') }
  40
+
  41
+    it "can find a created subscription" do
  42
+      Braintree::Subscription.find(subscription_result.subscription.id).should be
  43
+    end
  44
+
  45
+    it "raises a Braintree:NotFoundError when it cannot find a subscription" do
  46
+      expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/)
  47
+    end
  48
+  end
  49
+end

0 notes on commit cc7463f

Please sign in to comment.
Something went wrong with that request. Please try again.