Skip to content

Commit

Permalink
Add test for generating time entries
Browse files Browse the repository at this point in the history
  • Loading branch information
BuJo committed Sep 1, 2020
1 parent 388d071 commit 509ce9d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/timesheet_examples.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'tempfile'

require 'buchungsstreber/parser'

RSpec.shared_examples 'a timesheet parser' do |extension, templates|
Expand Down Expand Up @@ -39,4 +41,29 @@
expect { described_class.new(templates || {}).parse("spec/examples/invalid_time#{extension}") }.to raise_exception(/invalid time/)
end
end

context 'generating' do
it 'can render time entries' do
e = [{ issue: '1234', activity: 'Dev', text: 'asdf', time: 0.5, date: Date.parse('1970-01-01') }]
expect(described_class.new(templates || {}).format(e)).to include('asdf')
end

it 'produces something the same parser can parse' do
parser = described_class.new(templates || {})
e1 = [{ issue: '1234', activity: 'Dev', text: 'asdf', time: 0.5, date: Date.parse('1970-01-01') }]
str = parser.format(e1)

file = Tempfile.new('foo')
begin
file.write(str)
file.close
e2 = parser.parse(file.path)
e1[0].each do |k,v|
expect(e2[0][k]).to eq(v)
end
ensure
file.unlink
end
end
end
end

0 comments on commit 509ce9d

Please sign in to comment.