You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All Rspec tests are passing but the program will not load.
Story
As a User,
I would like to create an account
Spec
Code in the person.rb file:
require './lib/person.rb'
require './lib/atm.rb'
describe Person do
subject { described_class.new(name: 'Thomas') }
it 'is expected to have a :name on initialize' do
expect(subject.name).not_to be nil
end
it 'is expected to raise an error if no name is set' do
expect { described_class.new }.to raise_error 'A name is required'
end
it 'is expected to have a :cash attribute with the value of 0 on initialize' do
expect(subject.cash).to eq 0
end
it 'is expected to have a :account attribute' do
expect(subject.account).to be nil
end
describe 'can create an Account' do
before { subject.create_account }
it 'of Account class ' do
expect(subject.account).to be_an_instance_of Account
end
it 'with himself as an owner' do
expect(subject.account.owner).to be_an_instance_of Person
end
it 'owner is the current subject' do
expect(subject.account.owner).to eq subject
end
end
describe 'can manage funds if an account has been created' do
let(:atm) { Atm.new }
before { subject.create_account }
it 'can deposit funds' do
expect(subject.deposit(100)).to be_truthy
end
it 'funds are added to the account balance - deducted from cash' do
subject.cash = 100
subject.deposit(100)
expect(subject.cash).to be 0
end
it 'can withdraw funds' do
command = lambda { subject.withdraw(amount: 100, pin: subject.account.pin_code, account: subject.account, atm: atm) }
expect(command.call).to be_truthy
end
it 'withdraw is expected to raise an error if no ATM is passed in' do
command = lambda { subject.withdraw(amount: 100, pin: subject.account.pin_code, account: subject.account) }
expect { command.call }.to raise_error 'An ATM is required'
end
it 'funds are added to cash - deducted from account balance' do
subject.cash = 100
subject.deposit(100)
subject.withdraw(amount: 100, pin: subject.account.pin_code, account: subject.account, atm: atm)
expect(subject.cash).to be 100
end
end
describe 'cannot manage funds if no account has been created' do
it 'cannot deposit funds' do
expect { subject.deposit(100) }.to raise_error(RuntimeError, 'No account present')
end
end
end
Implementation code
Here is our code for the account.rb file:
attr_accessor :pin_code, :exp_date, :account_status, :balance, :owner
STANDARD_VALIDITY_YRS = 5
def initialize(attrs = {})
@balance = 1000
@account_status = :active
@owner = set_owner(attrs[:owner])
@pin_code = set_pin_code()
@exp_date = set_expire_date()
end
def deactivate
@account_status = :deactivated
end
private
def set_expire_date
Date.today.next_year(Account::STANDARD_VALIDITY_YRS).strftime('%m/%y')
end
def set_pin_code
rand(1000..9999)
end
def set_owner(obj)
obj == nil ? missing_owner : @owner = obj
end
def missing_owner
raise "An Account owner is required"
end
end
```
### Screenshots
```[1] pry(main)> load './lib/atm.rb'
=> true
[2] pry(main)> atm = Atm.new
=> #<Atm:0x00007fcfd2a2fe50 @funds=1000>
[3] pry(main)> person = Person.new(name: 'Thomas')
NameError: uninitialized constant Person
from (pry):3:in `__pry__'
[4] pry(main)> exit```
### How did you try to solve the problem?
Checked the person.rb file to identify issues. Cannot determine why we cannot create an account given that the Person class was initialized.
The text was updated successfully, but these errors were encountered:
Problem
We are getting the following error in pry:
NameError: uninitialized constant Person
Background
All Rspec tests are passing but the program will not load.
Story
Spec
Code in the person.rb file:
Implementation code
Here is our code for the account.rb file:
The text was updated successfully, but these errors were encountered: