timert 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ require_relative '../lib/timert/duration'
2
+
3
+ describe Timert::Duration do
4
+
5
+ it 'should have a method that returns the number of hours' do
6
+ expect(Timert::Duration.new(3 * 60 * 60 + 2 * 60).hours).to eq(3)
7
+ end
8
+
9
+ it 'should have a method that returns the number of minutes' do
10
+ expect(Timert::Duration.new(3 * 60 * 60 + 2 * 60).minutes).to eq(2)
11
+ end
12
+
13
+ it 'should have a method that returns the number of seconds' do
14
+ expect(Timert::Duration.new(2 * 60 + 55).seconds).to eq(55)
15
+ end
16
+
17
+ it 'should have a method that creates new object from given hours, minutes and seconds' do
18
+ expect(Timert::Duration.from(2, 5, 10).hours).to eq(2)
19
+ expect(Timert::Duration.from(2, 5, 10).minutes).to eq(5)
20
+ expect(Timert::Duration.from(2, 5, 10).seconds).to eq(10)
21
+ end
22
+
23
+ it 'should return formatted total elapsed time' do
24
+ expect(Timert::Duration.from(5, 45, 5).to_s).to eq("5h 45min 5sec")
25
+ expect(Timert::Duration.from(15, 0, 56).to_s).to eq("15h 0min 56sec")
26
+ end
27
+
28
+ it 'should have a method that returns rounded duration when a full-hour duration is passed' do
29
+ expect(Timert::Duration.from(4, 0, 0).round).to eq("4.0")
30
+ end
31
+
32
+ it 'should have a method that returns rounded, decimal duration' do
33
+ expect(Timert::Duration.from(5, 13, 12).round).to eq("5.0")
34
+ expect(Timert::Duration.from(5, 15, 12).round).to eq("5.5")
35
+ expect(Timert::Duration.from(5, 35, 12).round).to eq("5.5")
36
+ expect(Timert::Duration.from(5, 46, 12).round).to eq("6.0")
37
+ expect(Timert::Duration.from(5, 59, 12).round).to eq("6.0")
38
+ end
39
+
40
+ end
@@ -0,0 +1,83 @@
1
+ require 'timecop'
2
+
3
+ require_relative '../lib/timert/report'
4
+
5
+ describe Timert::Report do
6
+ let(:today) { Date.new(2013, 2, 20) }
7
+ let(:yesteday) { Date.new(2013, 2, 19) }
8
+ let(:database) { double }
9
+
10
+ let(:first_day) do
11
+ double(total_elapsed_time: 3.5 * 3600,
12
+ date: today,
13
+ tasks: ["emails", "meeting"],
14
+ intervals: [
15
+ {"start" => time(today, 16), "stop" => time(today, 18, 30)},
16
+ {"start" => time(today, 19), "stop" => time(today, 20)}
17
+ ])
18
+ end
19
+
20
+ let(:second_day) do
21
+ double(total_elapsed_time: 7 * 3600,
22
+ date: yesteday,
23
+ tasks: ["reports", "bugs"],
24
+ intervals: [
25
+ {"start" => time(yesteday, 11, 30), "stop" => time(yesteday, 16)},
26
+ {"start" => time(yesteday, 16, 30), "stop" => time(yesteday, 19, 30)}
27
+ ])
28
+ end
29
+
30
+ before(:each) do
31
+ Timecop.freeze(today)
32
+ end
33
+
34
+ after(:each) do
35
+ Timecop.return
36
+ end
37
+
38
+ it 'should generate report for today' do
39
+ database.should_receive(:day).with(today).and_return(first_day)
40
+
41
+ report = Timert::Report.generate(database)
42
+ expect(report.include?("2013-02-20")).to eq(true)
43
+ expect(report.include?("emails")).to eq(true)
44
+ expect(report.include?("meeting")).to eq(true)
45
+ expect(report.include?("3.5")).to eq(true)
46
+ end
47
+
48
+ it 'should generate report for any past day' do
49
+ database.should_receive(:day).with(yesteday).and_return(second_day)
50
+
51
+ report = Timert::Report.generate(database, -1)
52
+ expect(report.include?("2013-02-19")).to eq(true)
53
+ expect(report.include?("reports")).to eq(true)
54
+ expect(report.include?("bugs")).to eq(true)
55
+ expect(report.include?("7")).to eq(true)
56
+ end
57
+
58
+ it 'should generate report for this week' do
59
+ database.should_receive(:days).and_return([first_day, second_day])
60
+
61
+ report = Timert::Report.generate(database, "week")
62
+ expect(report.include?("WEEK")).to eq(true)
63
+ expect(report.include?("2013-02-19")).to eq(true)
64
+ expect(report.include?("2013-02-20")).to eq(true)
65
+ expect(report.include?("Total")).to eq(true)
66
+ expect(report.include?("10.5")).to eq(true)
67
+ end
68
+
69
+ it 'should generate report for this month' do
70
+ database.should_receive(:days).and_return([first_day, second_day])
71
+
72
+ report = Timert::Report.generate(database, "month")
73
+ expect(report.include?("MONTH")).to eq(true)
74
+ expect(report.include?("2013-02-19")).to eq(true)
75
+ expect(report.include?("2013-02-20")).to eq(true)
76
+ expect(report.include?("Total")).to eq(true)
77
+ expect(report.include?("10.5")).to eq(true)
78
+ end
79
+
80
+ def time(day, hours, minutes = 0, seconds = 0)
81
+ day.to_time.to_i + hours * 3600 + minutes * 60 + seconds
82
+ end
83
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'timecop'
3
+ require_relative '../lib/timert/timer'
4
+ require_relative '../lib/timert/day'
5
+
6
+ describe Timert::Timer do
7
+ before(:each) do
8
+ @today = Timert::Day.new
9
+ @timer = Timert::Timer.new(@today)
10
+ end
11
+
12
+ it 'should return start time when started' do
13
+ Timecop.freeze(Time.new(2013, 2, 14, 22, 0)) do
14
+ expect(@timer.start[:time]).to eq(Time.now.to_i)
15
+ end
16
+ end
17
+
18
+ context 'while running' do
19
+ before do
20
+ Timecop.freeze(Time.new(2013, 2, 14, 22, 0))
21
+ @timer.start
22
+ end
23
+
24
+ after do
25
+ Timecop.return
26
+ end
27
+
28
+ it "should not start again until it's stopped" do
29
+ time = Time.now.to_i
30
+ expect(@timer.start(time)[:started]).not_to eq(true)
31
+ expect(@timer.start(time + 10)[:started]).not_to eq(true)
32
+ @timer.stop
33
+ expect(@timer.start(time + 10)[:started]).to eq(true)
34
+ end
35
+
36
+ context 'and then stopped' do
37
+ it 'should return stop time' do
38
+ Timecop.freeze(Time.new(2013, 2, 14, 23, 0)) do
39
+ expect(@timer.stop[:time]).to eq(Time.now.to_i)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'while not running' do
46
+ it "should not stop until it's started" do
47
+ expect(@timer.stop[:stopped]).not_to eq(true)
48
+ @timer.start
49
+ expect(@timer.stop[:stopped]).to eq(true)
50
+ end
51
+ end
52
+
53
+ it 'should be able to start with given time' do
54
+ time = Time.now.to_i
55
+ expect(@timer.start(time)[:time]).to eq(time)
56
+ end
57
+
58
+ it 'should be able to stop with given time' do
59
+ @timer.start
60
+ time = Time.now.to_i + 500
61
+ expect(@timer.stop(time)[:time]).to eq(time)
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timert
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gosia Kwidzinska
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: timecop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Timert is a simple time tracking tool for the console. If necessary you
56
+ can specify a time you want the timer to start or to stop. The tool provides also
57
+ summary reports for a given day, week or month
58
+ email: g.kwidzinska@gmail.com
59
+ executables:
60
+ - timert
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - bin/timert
65
+ - lib/timert.rb
66
+ - lib/timert/duration.rb
67
+ - lib/timert/help.rb
68
+ - lib/timert/database_file.rb
69
+ - lib/timert/day.rb
70
+ - lib/timert/timer.rb
71
+ - lib/timert/application.rb
72
+ - lib/timert/report.rb
73
+ - lib/timert/argument_parser.rb
74
+ - lib/timert/date_util.rb
75
+ - lib/timert/database.rb
76
+ - spec/day_spec.rb
77
+ - spec/application_spec.rb
78
+ - spec/timer_spec.rb
79
+ - spec/duration_spec.rb
80
+ - spec/report_spec.rb
81
+ - spec/database_file_spec.rb
82
+ - spec/argument_parser_spec.rb
83
+ - spec/date_util_spec.rb
84
+ - spec/database_spec.rb
85
+ homepage: http://rubygems.org/gems/timert
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Timert is a simple time tracking tool for the console.
108
+ test_files:
109
+ - spec/day_spec.rb
110
+ - spec/application_spec.rb
111
+ - spec/timer_spec.rb
112
+ - spec/duration_spec.rb
113
+ - spec/report_spec.rb
114
+ - spec/database_file_spec.rb
115
+ - spec/argument_parser_spec.rb
116
+ - spec/date_util_spec.rb
117
+ - spec/database_spec.rb