How to Synchronize

In our current implementation, the debit and credit transactions are processed synchronously by our simplistic Account class:

support_code/18/lib/nice_bank.rb
 
class​ Account
 
def​ credit(amount)
 
@balance = amount
 
end
 
 
def​ balance
 
@balance
 
end
 
 
def​ debit(amount)
 
@balance -= amount
 
end
 
end

This implementation, where the balance is updated during the method call to credit or debit, means that we can be certain the balance will have been updated by the time Cucumber checks the account balance in the final Then step of our scenario.

support_code/18/features/cash_withdrawal.feature
 
Feature:​ Cash Withdrawal​​
 
Scenario:​ Successful withdrawal from an account in credit​​
 
Given ​my account ...

Get The Cucumber Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.