summaryrefslogtreecommitdiff
path: root/test/test_timetrackr.rb
blob: 07589a4f48dfe7ca18bc7e44beef85525805eec2 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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

  context 'an Sqlite based tracker' do
    setup do
      @config = {:path => '/tmp/timetracker.test'}
      @t = TimeTrackr.create('sqlite',@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 '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