-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_spec.rb
66 lines (54 loc) · 1.81 KB
/
account_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative "account"
describe Account do
let(:valid_account_number) { "1234567890" }
let(:account) { Account.new(valid_account_number) }
describe "#initialize" do
it "should be a valid account number" do
expect(account.acct_number).to eq("******7890")
end
it "should raise InvalidAccountNumebrError" do
expect { Account.new('qwertyuuiiop') }.to raise_error(InvalidAccountNumberError)
end
it "should have a starting balance of 0" do
expect(account.balance).to eq(0)
end
end
describe "#transactions" do
it "should make a deposit and increase the balance" do
expect(account.deposit!(500)).to eq(500)
end
it "should make a withdrawal and decrease the balance" do
expect(Account.new("0987654321", 500).withdraw!(200)).to eq(300)
end
it "should raise a OverdraftError for withdrawing" do
expect { Account.new("0987654321", 20).withdraw!(21) }.to raise_error(OverdraftError)
end
it "should raise a NegativeDepositError for depositing a negative balance" do
expect { Account.new("0987654321", 50).deposit!(-25) }.to raise_error(NegativeDepositError)
end
end
describe "#balance" do
it "should return 0" do
expect(account.balance).to eq(0)
end
it "should return the sum of transactions" do
account.should_receive(:transactions) { [10, 20]}
expect(account.balance).to eq(30)
end
end
describe "#account_number" do
it "should mask an account number" do
expect(account.acct_number).to include('******')
end
end
describe "deposit!" do
it "should make a deposit" do
expect(account.deposit!(100)).to eq(100)
end
end
describe "#withdraw!" do
it "should make a withdrawal" do
expect(Account.new("0987654321", 100).withdraw!(50) ).to eq(50)
end
end
end