From aafe662acba563db43005121212561e781c51270 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 11 Aug 2013 15:06:08 -0400 Subject: [PATCH] rspec Account --- lib/gnucash/account.rb | 2 +- spec/gnucash/account_spec.rb | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 spec/gnucash/account_spec.rb diff --git a/lib/gnucash/account.rb b/lib/gnucash/account.rb index 3413ba8..a62a798 100644 --- a/lib/gnucash/account.rb +++ b/lib/gnucash/account.rb @@ -49,7 +49,7 @@ module Gnucash end end - def current_balance + def final_balance return Value.new(0) unless @balances.size > 0 @balances.last[:value] end diff --git a/spec/gnucash/account_spec.rb b/spec/gnucash/account_spec.rb new file mode 100644 index 0000000..7d6d15d --- /dev/null +++ b/spec/gnucash/account_spec.rb @@ -0,0 +1,40 @@ +module Gnucash + describe Account do + before(:all) do + # just read the file once + @book = Gnucash.open("spec/books/sample.gnucash") + @checking = @book.find_account_by_full_name("Assets::Current Assets::Checking Account") + @salary = @book.find_account_by_full_name("Income::Salary") + end + + it "gives access to the account name" do + @salary.name.should == "Salary" + end + + it "gives access to the fully-qualified account name" do + @checking.full_name.should == "Assets::Current Assets::Checking Account" + end + + it "gives access to the final balance" do + @checking.final_balance.should == Value.new(19743000) + end + + describe '.balance_on' do + it "returns 0 if the given date is before the account's first transaction" do + @checking.balance_on("2006-12-12").should == Value.new(0) + end + + it "returns the final balance if the given date is after the account's last transaction" do + @checking.balance_on("2013-10-10").should == @checking.final_balance + end + + it "returns the balance on the given date" do + @checking.balance_on("2012-12-25").should == Value.new(19688000) + end + + it "includes transactions that occur on the given date" do + @checking.balance_on("2007-03-27").should == Value.new(780000) + end + end + end +end