Sha256: cbdd4737a1e8fdeb58ef64f44d42680d07afb6d4ff8bcc5075efdb2ac3cdaf64

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module Gnucash
  describe Book do
    context "with errors" do
      it "raises an error for unexpected XML" do
        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

    context "without errors" do
      before(:all) do
        # just open the test file once
        @subject = Gnucash.open("spec/books/sample.gnucash")
      end

      it "records the date of the earliest transaction" do
        @subject.start_date.should == "2007-01-01"
      end

      it "records the date of the last transaction" do
        @subject.end_date.should == "2012-12-28"
      end

      it "lets you find an account by id" do
        @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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gnucash-1.1.0 spec/gnucash/book_spec.rb
gnucash-1.0.3 spec/gnucash/book_spec.rb
gnucash-1.0.2 spec/gnucash/book_spec.rb
gnucash-1.0.1 spec/gnucash/book_spec.rb
gnucash-1.0.0 spec/gnucash/book_spec.rb