Skip to content

Commit 67a6f62

Browse files
committed
Format using Rubocop & add simpleCov to check code test coverage
1 parent 6f8c870 commit 67a6f62

File tree

12 files changed

+94
-87
lines changed

12 files changed

+94
-87
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ source 'https://rubygems.org'
55
# gem "rails"
66

77
gem 'rspec', '~> 3.12'
8+
9+
# gem "simplecov"
10+
11+
gem 'simplecov', require: false, group: :test

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ GEM
22
remote: https://rubygems.org/
33
specs:
44
diff-lcs (1.5.0)
5+
docile (1.4.0)
56
rspec (3.12.0)
67
rspec-core (~> 3.12.0)
78
rspec-expectations (~> 3.12.0)
@@ -15,12 +16,19 @@ GEM
1516
diff-lcs (>= 1.2.0, < 2.0)
1617
rspec-support (~> 3.12.0)
1718
rspec-support (3.12.0)
19+
simplecov (0.21.2)
20+
docile (~> 1.1)
21+
simplecov-html (~> 0.11)
22+
simplecov_json_formatter (~> 0.1)
23+
simplecov-html (0.12.3)
24+
simplecov_json_formatter (0.1.4)
1825

1926
PLATFORMS
2027
arm64-darwin-21
2128

2229
DEPENDENCIES
2330
rspec (~> 3.12)
31+
simplecov
2432

2533
BUNDLED WITH
2634
2.3.26

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1> Banking App <h1>
2-
<h4>A tech test to practice code quality. <h4>
32
<div>
3+
A tech test to practice code quality.
44
<h5>
55
<a href='https://github.com/kwatts949/banking_app/blob/main/README.md#Specification'> Specification </a> <span> · </span>
66
<a href='https://github.com/kwatts949/banking_app/blob/main/README.md#Installation'> Installation </a><span> · </span>
@@ -78,6 +78,7 @@ Example output: <br>
7878

7979
To run the tests:
8080
```
81+
$ cd banking_app
8182
$ rspec
8283
```
8384

lib/account.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,3 @@ def print_statement
2323
@statement.display(@transactions)
2424
end
2525
end
26-
27-
=begin
28-
account = Account.new
29-
30-
transaction_1 = Transaction.new(1000, "10-01-2023")
31-
transaction_2 = Transaction.new(2000, "13-01-2023")
32-
transaction_3 = Transaction.new(500, "14-01-2023")
33-
34-
account.deposit(transaction_1)
35-
account.deposit(transaction_2)
36-
account.withdraw(transaction_3)
37-
38-
account.print_statement
39-
=end

lib/statement.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def print_transactions(transactions)
2424
end
2525

2626
def print_header
27-
p "date || credit || debit || balance"
27+
p 'date || credit || debit || balance'
2828
end
2929

3030
def print_empty

resources/.DS_Store

0 Bytes
Binary file not shown.

spec/account_spec.rb

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,38 @@
99
context 'making a withdrawal' do
1010
it 'returns an array of withdrawal objects' do
1111
account = Account.new
12-
fake_withdrawal_1 = double(amount: 500, date: "01-12-2022", credit: nil)
13-
fake_withdrawal_2 = double(amount: 700, date: "02-12-2022", credit: nil)
14-
account.withdraw(fake_withdrawal_1)
15-
account.withdraw(fake_withdrawal_2)
16-
expect(account.transactions).to eq [fake_withdrawal_1, fake_withdrawal_2]
12+
fake_withdrawal1 = double(amount: 500, date: '01-12-2022', credit: nil)
13+
fake_withdrawal2 = double(amount: 700, date: '02-12-2022', credit: nil)
14+
account.withdraw(fake_withdrawal1)
15+
account.withdraw(fake_withdrawal2)
16+
expect(account.transactions).to eq [fake_withdrawal1, fake_withdrawal2]
1717
end
1818
end
1919

2020
context 'making a deposit' do
2121
it 'returns an array of deposit objects' do
2222
account = Account.new
23-
fake_deposit_1 = double(amount: 1000, date: "01-12-2022", credit: nil)
24-
fake_deposit_2 = double(amount: 700, date: "02-12-2022", credit: nil)
25-
expect(fake_deposit_1).to receive(:credit=).with('true')
26-
account.deposit(fake_deposit_1)
27-
expect(fake_deposit_2).to receive(:credit=).with('true')
28-
account.deposit(fake_deposit_2)
29-
expect(account.transactions).to eq [fake_deposit_1, fake_deposit_2]
23+
fake_deposit1 = double(amount: 1000, date: '01-12-2022', credit: nil)
24+
fake_deposit2 = double(amount: 700, date: '02-12-2022', credit: nil)
25+
expect(fake_deposit1).to receive(:credit=).with('true')
26+
account.deposit(fake_deposit1)
27+
expect(fake_deposit2).to receive(:credit=).with('true')
28+
account.deposit(fake_deposit2)
29+
expect(account.transactions).to eq [fake_deposit1, fake_deposit2]
3030
end
3131
end
3232

3333
context 'making a deposit & withdrawal' do
3434
it 'returns an array of objects' do
3535
account = Account.new
3636

37-
fake_deposit_1 = double(amount: 1000, date: "01-12-2022", credit: 'true')
38-
fake_withdrawal_1 = double(amount: 500, date: "01-12-2022", credit: nil)
37+
fake_deposit1 = double(amount: 1000, date: '01-12-2022', credit: 'true')
38+
fake_withdrawal1 = double(amount: 500, date: '01-12-2022', credit: nil)
3939

40-
expect(fake_deposit_1).to receive(:credit=).with('true')
41-
account.deposit(fake_deposit_1)
42-
account.withdraw(fake_withdrawal_1)
43-
44-
expect(account.transactions).to eq [fake_deposit_1, fake_withdrawal_1]
40+
expect(fake_deposit1).to receive(:credit=).with('true')
41+
account.deposit(fake_deposit1)
42+
account.withdraw(fake_withdrawal1)
43+
expect(account.transactions).to eq [fake_deposit1, fake_withdrawal1]
4544
end
4645
end
4746

@@ -50,26 +49,26 @@
5049
account = Account.new
5150
expect do
5251
account.print_statement
53-
end.to output( "\"date || credit || debit || balance\"\n\" || || || 0.00\"\n").to_stdout
52+
end.to output("\"date || credit || debit || balance\"\n\" || || || 0.00\"\n").to_stdout
5453
end
5554

5655
it 'returns a statement with deposits and withdrawals' do
5756
account = Account.new
5857

59-
fake_deposit_1 = double(amount: 1000, date: "01-12-2022", credit: 'true')
60-
fake_deposit_2 = double(amount: 2000, date: "02-12-2022", credit: 'true')
61-
fake_withdrawal_1 = double(amount: 500, date: "03-12-2022", credit: nil)
58+
fake_deposit1 = double(amount: 1000, date: '01-12-2022', credit: 'true')
59+
fake_deposit2 = double(amount: 2000, date: '02-12-2022', credit: 'true')
60+
fake_withdrawal1 = double(amount: 500, date: '03-12-2022', credit: nil)
6261

63-
expect(fake_deposit_1).to receive(:credit=).with('true')
64-
expect(fake_deposit_2).to receive(:credit=).with('true')
62+
expect(fake_deposit1).to receive(:credit=).with('true')
63+
expect(fake_deposit2).to receive(:credit=).with('true')
6564

66-
account.deposit(fake_deposit_1)
67-
account.deposit(fake_deposit_2)
68-
account.withdraw(fake_withdrawal_1)
65+
account.deposit(fake_deposit1)
66+
account.deposit(fake_deposit2)
67+
account.withdraw(fake_withdrawal1)
6968

7069
expect do
7170
account.print_statement
7271
end.to output("\"date || credit || debit || balance\"\n\"03-12-2022 || || 500.00 || 2500.00\"\n\"02-12-2022 || 2000.00 || || 3000.00\"\n\"01-12-2022 || 1000.00 || || 1000.00\"\n").to_stdout
7372
end
7473
end
75-
end
74+
end

spec/integration_tests_spec.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
end
1212

1313
it 'returns a multiple deposit transaction' do
14-
transaction_1 = Transaction.new(500, '10-12-2022')
15-
transaction_2 = Transaction.new(300, '12-12-2022')
14+
transaction1 = Transaction.new(500, '10-12-2022')
15+
transaction2 = Transaction.new(300, '12-12-2022')
1616
account = Account.new
17-
account.deposit(transaction_1)
18-
account.deposit(transaction_2)
19-
expect(account.transactions).to eq [transaction_1, transaction_2]
17+
account.deposit(transaction1)
18+
account.deposit(transaction2)
19+
expect(account.transactions).to eq [transaction1, transaction2]
2020
end
2121
end
2222

@@ -30,12 +30,12 @@
3030
end
3131

3232
it 'returns multiple withdrawal transaction' do
33-
transaction_1 = Transaction.new(500, '10-12-2022')
34-
transaction_2 = Transaction.new(300, '12-12-2022')
33+
transaction1 = Transaction.new(500, '10-12-2022')
34+
transaction2 = Transaction.new(300, '12-12-2022')
3535
account = Account.new
36-
account.withdraw(transaction_1)
37-
account.withdraw(transaction_2)
38-
expect(account.transactions).to eq [transaction_1, transaction_2]
36+
account.withdraw(transaction1)
37+
account.withdraw(transaction2)
38+
expect(account.transactions).to eq [transaction1, transaction2]
3939
end
4040

4141
context 'printing a statement' do
@@ -48,41 +48,41 @@
4848

4949
it 'returns a statement containing a deposit' do
5050
account = Account.new
51-
transaction_1 = Transaction.new(500, '10-12-2022')
52-
account.deposit(transaction_1)
51+
transaction1 = Transaction.new(500, '10-12-2022')
52+
account.deposit(transaction1)
5353
expect do
5454
account.print_statement
5555
end.to output("\"date || credit || debit || balance\"\n\"10-12-2022 || 500.00 || || 500.00\"\n").to_stdout
5656
end
5757

5858
it 'returns a statement containing two deposits' do
5959
account = Account.new
60-
transaction_1 = Transaction.new(500, '10-12-2022')
61-
transaction_2 = Transaction.new(300, '12-12-2022')
62-
account.deposit(transaction_1)
63-
account.deposit(transaction_2)
60+
transaction1 = Transaction.new(500, '10-12-2022')
61+
transaction2 = Transaction.new(300, '12-12-2022')
62+
account.deposit(transaction1)
63+
account.deposit(transaction2)
6464
expect do
6565
account.print_statement
6666
end.to output("\"date || credit || debit || balance\"\n\"12-12-2022 || 300.00 || || 800.00\"\n\"10-12-2022 || 500.00 || || 500.00\"\n").to_stdout
6767
end
6868

6969
it 'returns a statement containing a withdrawal' do
7070
account = Account.new
71-
transaction_1 = Transaction.new(500, '10-12-2022')
72-
account.withdraw(transaction_1)
71+
transaction1 = Transaction.new(500, '10-12-2022')
72+
account.withdraw(transaction1)
7373
expect do
7474
account.print_statement
7575
end.to output("\"date || credit || debit || balance\"\n\"10-12-2022 || || 500.00 || -500.00\"\n").to_stdout
7676
end
7777

7878
it 'returns a statement containing withdrawals and deposits' do
7979
account = Account.new
80-
transaction_1 = Transaction.new(500, '10-12-2022')
81-
transaction_2 = Transaction.new(300, '12-12-2022')
82-
transaction_3 = Transaction.new(100, '12-12-2022')
83-
account.deposit(transaction_1)
84-
account.withdraw(transaction_2)
85-
account.deposit(transaction_3)
80+
transaction1 = Transaction.new(500, '10-12-2022')
81+
transaction2 = Transaction.new(300, '12-12-2022')
82+
transaction3 = Transaction.new(100, '12-12-2022')
83+
account.deposit(transaction1)
84+
account.withdraw(transaction2)
85+
account.deposit(transaction3)
8686
expect do
8787
account.print_statement
8888
end.to output("\"date || credit || debit || balance\"\n\"12-12-2022 || 100.00 || || 300.00\"\n\"12-12-2022 || || 300.00 || 200.00\"\n\"10-12-2022 || 500.00 || || 500.00\"\n").to_stdout

0 commit comments

Comments
 (0)