Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example issue/template] NoMethodError in withdraw method #2

Open
faraznaeem opened this issue Jan 29, 2018 · 1 comment
Open

[example issue/template] NoMethodError in withdraw method #2

faraznaeem opened this issue Jan 29, 2018 · 1 comment

Comments

@faraznaeem
Copy link
Contributor

[Issue template]

Problem

Getting an undefined method error when running RSpec

Background

I was refactoring my code and I added a case statement to my withdraw method and now I am getting an undefined method error

Story

As a User,
In order to access my funds,
I would like to make a withdrawal.

Spec

  it 'funds are reduced at withdraw' do
    subject.withdraw( 50, '1234', account)
    expect(subject.funds).to eq 950
  end

Implementation code

  def withdrawal(amount, pin_code, account)
    case
      when insufficent_funds_in_account(amount, account)
        { status: false, message: 'insufficient funds', date: Date.today }
      when insufficent_funds_in_ATM(amount)
        { status: false, message: 'insufficient funds in ATM', date: Date.today }
      when incorrect_pin?(pin_code, account.pin_code)
        { status: false, message: 'wrong pin', date: Date.today }
      when card_expired?(account.exp_date)
        { status: false, message: 'card expired', date: Date.today }
      else
        perform_the_transaction(amount, account)
    end
  end

Screenshots

screen shot 2018-01-29 at 16 09 31

How did you try to solve the problem?

  • I went through all the syntax
  • Rewrote the method
@faraznaeem
Copy link
Contributor Author

faraznaeem commented Jan 29, 2018

Hi, you are getting the NoMethodError because you are using withdraw in the spec and withdrawalin the case method. You will need to change either the spec or the case statement to resolve the issue. This occurs sometimes when you use the autocomplete function in your favorite text editor.

@faraznaeem faraznaeem changed the title [example issue] NoMethodError in withdraw method [example issue/template] NoMethodError in withdraw method Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant