Skip to content

Commit 3d4824b

Browse files
committed
refactor(transfers-methods/spec): Better mocks for unit tests of methods
1 parent 5342981 commit 3d4824b

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

spec/lib/fintoc/transfers/account_numbers_methods_spec.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ def patch(*, **)
3030

3131
describe '#create_account_number' do
3232
before do
33-
allow(client).to receive(:build_account_number)
33+
allow(Fintoc::Transfers::AccountNumber).to receive(:new)
3434
end
3535

3636
it 'calls build_account_number with the response' do
3737
client.create_account_number(account_id: 'acc_123')
38-
expect(client).to have_received(:build_account_number).with({ mock: 'response' })
38+
expect(Fintoc::Transfers::AccountNumber)
39+
.to have_received(:new).with(mock: 'response', client:)
3940
end
4041
end
4142

4243
describe '#get_account_number' do
4344
before do
44-
allow(client).to receive(:build_account_number)
45+
allow(Fintoc::Transfers::AccountNumber).to receive(:new)
4546
end
4647

4748
it 'calls build_account_number with the response' do
4849
client.get_account_number('acno_123')
49-
expect(client).to have_received(:build_account_number).with({ mock: 'response' })
50+
expect(Fintoc::Transfers::AccountNumber)
51+
.to have_received(:new).with(mock: 'response', client:)
5052
end
5153
end
5254

@@ -55,24 +57,27 @@ def patch(*, **)
5557
allow(client)
5658
.to receive(:_list_account_numbers)
5759
.and_return([{ mock: 'response1' }, { mock: 'response2' }])
58-
allow(client).to receive(:build_account_number)
60+
allow(Fintoc::Transfers::AccountNumber).to receive(:new)
5961
end
6062

6163
it 'calls build_account_number for each response' do
6264
client.list_account_numbers
63-
expect(client).to have_received(:build_account_number).with({ mock: 'response1' })
64-
expect(client).to have_received(:build_account_number).with({ mock: 'response2' })
65+
expect(Fintoc::Transfers::AccountNumber)
66+
.to have_received(:new).with(mock: 'response1', client:)
67+
expect(Fintoc::Transfers::AccountNumber)
68+
.to have_received(:new).with(mock: 'response2', client:)
6569
end
6670
end
6771

6872
describe '#update_account_number' do
6973
before do
70-
allow(client).to receive(:build_account_number)
74+
allow(Fintoc::Transfers::AccountNumber).to receive(:new)
7175
end
7276

7377
it 'calls build_account_number with the response' do
7478
client.update_account_number('acno_123', description: 'Updated')
75-
expect(client).to have_received(:build_account_number).with({ mock: 'response' })
79+
expect(Fintoc::Transfers::AccountNumber)
80+
.to have_received(:new).with(mock: 'response', client:)
7681
end
7782
end
7883
end

spec/lib/fintoc/transfers/simulation_methods_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def post(*, **)
2222

2323
describe '#simulate_receive_transfer' do
2424
before do
25-
allow(client).to receive(:build_transfer)
25+
allow(Fintoc::Transfers::Transfer).to receive(:new)
2626
end
2727

2828
it 'calls build_transfer with the response' do
@@ -31,7 +31,8 @@ def post(*, **)
3131
amount: 10000,
3232
currency: 'MXN'
3333
)
34-
expect(client).to have_received(:build_transfer).with({ mock: 'response' })
34+
expect(Fintoc::Transfers::Transfer)
35+
.to have_received(:new).with(mock: 'response', client:)
3536
end
3637
end
3738
end

0 commit comments

Comments
 (0)