summaryrefslogtreecommitdiff
path: root/test/test_timetrackr.rb
blob: 0c8a526373e15d34dcd819453c7d3e42d98f595f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'helper'

class TestTimetrackr < Test::Unit::TestCase
  context 'a YAML based tracker' do
    setup do
      @config = {:path => '/tmp/timetracker.test'}
      @t = TimeTrackr.create('yaml',@config)
    end

    def teardown
      File.unlink(@config[:path]) rescue nil
    end

    should 'initialise a log file' do
      assert File.exist?(@config[:path])
    end

    context 'with empty db' do
      setup do
        File.open(@config[:path]) do |fh|
          @db = YAML.load(fh)
        end
      end

      should 'create basic structure' do
        File.open(@config[:path]) do |fh|
          @db = YAML.load(fh)
        end
        assert @db[:current].class == Array
        assert @db[:tasks].class == Hash
      end

      should 'not fail on current command' do
        assert_nothing_raised Exception do
          @t.current
        end
      end

      should 'not fail on tasks command' do
        assert_nothing_raised Exception do
          @t.tasks
        end
      end

      should 'not fail on close command' do
        assert_nothing_raised Exception do
          @t.close
        end
      end

    end
  end
end