finish Book rspecs

This commit is contained in:
Josh Holtrop 2013-08-11 14:35:41 -04:00
parent 8b0b639434
commit febf4a9f6d

View File

@ -1,24 +1,39 @@
module Gnucash module Gnucash
describe Book do describe Book do
before(:all) do context "with errors" do
# just open the test file once it "raises an error for unexpected XML" do
@subject = Gnucash.open("spec/books/sample.gnucash") gr = "gr"
Zlib::GzipReader.should_receive(:open).and_return(gr)
gr.should_receive(:read).and_return(nil)
ng = "ng"
Nokogiri.should_receive(:XML).and_return(ng)
ng.should_receive(:xpath).with('/gnc-v2/gnc:book').and_return([])
expect { Gnucash::Book.new('file name') }.to raise_error "Error: Expected to find one gnc:book entry"
end
end end
it "records the date of the earliest transaction" do context "without errors" do
@subject.start_date.should == "2007-01-01" before(:all) do
end # just open the test file once
@subject = Gnucash.open("spec/books/sample.gnucash")
end
it "records the date of the last transaction" do it "records the date of the earliest transaction" do
@subject.end_date.should == "2012-12-28" @subject.start_date.should == "2007-01-01"
end end
it "lets you find an account by id" do it "records the date of the last transaction" do
@subject.find_account_by_id("67e6e7daadc35716eb6152769373e974").name.should == "Savings Account" @subject.end_date.should == "2012-12-28"
end end
it "lets you find an account by full name" do it "lets you find an account by id" do
@subject.find_account_by_full_name("Assets::Current Assets::Savings Account").id.should == "67e6e7daadc35716eb6152769373e974" @subject.find_account_by_id("67e6e7daadc35716eb6152769373e974").name.should == "Savings Account"
end
it "lets you find an account by full name" do
@subject.find_account_by_full_name("Assets::Current Assets::Savings Account").id.should == "67e6e7daadc35716eb6152769373e974"
end
end end
end end
end end