43 lines
1.3 KiB
Ruby
43 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# rubocop:disable RSpec/DescribeClass
|
|
RSpec.describe "Hledger integration" do
|
|
before { skip "hledger is not installed" if !Hledger::Runner.new.available? }
|
|
|
|
let(:journal) { File.read(Rails.root.join("plugins/hledger/spec/fixtures/journal.txt")) }
|
|
let(:builder) { Hledger::ReportBuilder.new }
|
|
|
|
it "builds every supported report" do
|
|
%w[accounts balance_sheet income_statement equity].each do |type|
|
|
expect(builder.build(type, journal: journal)["report_type"]).to eq(type)
|
|
end
|
|
end
|
|
|
|
it "treats the end date as inclusive" do
|
|
report =
|
|
builder.build(
|
|
"income_statement",
|
|
journal: journal,
|
|
begin_date: Date.new(2024, 1, 1),
|
|
end_date: Date.new(2024, 3, 15),
|
|
)
|
|
|
|
expect(report["net"].first["display"]).to eq("29.50 EUR")
|
|
end
|
|
|
|
it "computes the equity distribution" do
|
|
holders = builder.build("equity", journal: journal)["groups"].first["holders"]
|
|
|
|
expect(holders.map { |holder| [holder["holder"], holder["percentage"]] }).to eq(
|
|
[%w[alice 60.00], %w[bob 40.00]],
|
|
)
|
|
end
|
|
|
|
it "rejects journals with include directives" do
|
|
expect(Hledger::Journal.extract("```hledger\ninclude /etc/hostname\n```").error).to eq(
|
|
:include_not_allowed,
|
|
)
|
|
end
|
|
end
|
|
# rubocop:enable RSpec/DescribeClass
|