Maricvs / TestTask

0 stars 0 forks source link

Write tests for your code #6

Closed Stepandanci closed 4 years ago

Stepandanci commented 4 years ago

You write good test task but you can update it.

Your last task to write tests. 1) Read about Rspec. It is a framework for test your code.

2) Create Fibank_spec.rb file. In Fibank_spec.rb file describe class Fibank. Save 2 HTML files 'accounts.html' and 'transactions.html'.

3) Write specs for parse_accounts and parse_transactions. Show parsing results. Accounts and transactions count and a data example for 1 account and 1 transaction.

Code fragment example.

html     = # File Read 'accounts.html' with Nokogiri HTML
accounts = Fibank.parse_accounts(html)

expect(accounts.count).to eq(2)

expect(accounts[0].to_hash).to eq(
  {
    ...
  }
)

Instruction how to save html file

  1. press F12
  2. find element
  3. right click
  4. copy outerHTML
  5. save in accounts.html

accounts_html

Good luck.

Stepandanci commented 4 years ago

If you have any questions, ask them in this issue. I will answer tomorrow.

Maricvs commented 4 years ago

I was able to write a test only for Accounts count. The rest are a bit more complicated. I am looking for information and a solution.

Stepandanci commented 4 years ago

You started writing spec very well. Continue in the same spirit. I will give you a couple of tips.

Stepandanci commented 4 years ago

use method to_hash for show account

    expect(accounts[0].to_hash).to eq({
      "name"=>      ...,
      "currency"=>  ...,
      "balance"=>   ...,
    })
Stepandanci commented 4 years ago

1 Read about Rspec Let variables here http://pololu.github.io/rpicsim/file.IntroductionToRSpec.html 2 create account variable in spec

let(:account) { Account.new("example", "CUR", 0.0) } # Account.new(name, currency, balance)

it "parse_transactions" do
  # make transactions html
  # show transactions size
  # send `account` variable for parse_transactions

  transactions = parse_transactions(account, html)

  expect(transactions[0].to_hash).to eq({
    "date" =>        "2000-12-31",
    "description" => "description",
    "amount" =>      0.5
  })
Stepandanci commented 4 years ago

Try to complete your task until Friday for that we can contact with you.

Maricvs commented 4 years ago

Thanks for support. I spent all night on the task)

Stepandanci commented 4 years ago

Congratulations, You completed your test task!

Stepandanci commented 4 years ago

Your test task is ready. Do not merge your pull request yet.

Maricvs commented 4 years ago

Great! ok See you