diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/app_test.rb | 2 | ||||
| -rw-r--r-- | test/command_test.rb | 70 | ||||
| -rw-r--r-- | test/day_entry_test.rb | 6 | ||||
| -rw-r--r-- | test/test_helper.rb | 21 | ||||
| -rw-r--r-- | test/utility_test.rb | 6 |
5 files changed, 94 insertions, 11 deletions
diff --git a/test/app_test.rb b/test/app_test.rb index ec13e46..0b4c90b 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class AppTest < Test::Unit::TestCase - should "permit commands from the HCl::Commands module" do + def test_commands app = HCl::App.new assert HCl::Commands.instance_methods.all? { |c| app.command? c }, 'all methods are commands' end diff --git a/test/command_test.rb b/test/command_test.rb new file mode 100644 index 0000000..0b3b5c1 --- /dev/null +++ b/test/command_test.rb @@ -0,0 +1,70 @@ +require 'test_helper' +class CommandTest < Test::Unit::TestCase + include HCl::Commands + include HCl::Utility + + def setup + @settings = {} + end + + # the current_time utility method needs to be deterministic + def current_time + 'high noon' + end + + # stub settings helpers + def write_settings; end + def read_settings + @settings + end + + def test_tasks + HCl::Task.expects(:all).returns([HCl::Task.new( + id:123, + name: 'Dev', + project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b') + )]) + result = tasks + assert_equal "456 123\tBob - [b] App - Dev", result + end + + def test_show + HCl::DayEntry.expects(:all).returns([HCl::DayEntry.new({ + hours:'2.06', + notes: 'hi world', + project: 'App' + })]) + result = show + assert_equal \ + "\t2:03\tApp: hi world\n\t-------------\n\t2:03\ttotal (as of high noon)\n", + result + end + + def test_aliases + HCl::Task.expects(:all).returns([HCl::Task.new( + id:123, + name: 'Dev', + project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b') + )]) + result = send :alias, *%w[ hcl 456 123 ] + assert_equal '456 123', @settings['task.hcl'] + + result = aliases + assert_equal ["@hcl"], result + + result = unalias 'hcl' + assert !@settings.key?('task.hcl'), 'hcl alias is no longer defined' + end + + def test_start + task = HCl::Task.new( + id:123, + name: 'Dev', + project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b') + ) + HCl::Task.expects(:find).with('456','123').returns(task) + task.expects(:start).with(starting_time:nil, note:'do stuff') + start *%w[ 456 123 do stuff ] + end + +end diff --git a/test/day_entry_test.rb b/test/day_entry_test.rb index a0b49a4..3e3d06a 100644 --- a/test/day_entry_test.rb +++ b/test/day_entry_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class DayEntryTest < Test::Unit::TestCase - should "read DayEntry xml" do + def test_from_xml entries = HCl::DayEntry.from_xml(<<-EOD) <daily> <for_day type="date">Wed, 18 Oct 2006</for_day> @@ -33,14 +33,14 @@ class DayEntryTest < Test::Unit::TestCase end end - should "append to an existing note" do + def test_append_note entry = HCl::DayEntry.new(:id => '1', :notes => 'yourmom.', :hours => '1.0') HCl::DayEntry.stubs(:post) entry.append_note('hi world') assert_equal "yourmom.\nhi world", entry.notes end - should "append to an undefined note" do + def test_append_note_to_empty entry = HCl::DayEntry.new(:id => '1', :notes => nil, :hours => '1.0') HCl::DayEntry.stubs(:post) entry.append_note('hi world') diff --git a/test/test_helper.rb b/test/test_helper.rb index 450baa2..b8506ec 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,20 @@ -$:.unshift(File.dirname(__FILE__) + '/../lib') +require 'bundler' +require 'simplecov' +SimpleCov.start do + add_filter '/test/' + add_filter do |source_file| + source_file.lines.count < 15 + end +end -require 'rubygems' require 'test/unit' -require 'hcl' -require 'shoulda' require 'mocha/setup' + +# override the default hcl dir +FileUtils.mkdir_p __dir__+"/dot_hcl" +ENV['HCL_DIR'] = __dir__+"/dot_hcl" + +$:.unshift(__dir__ + '/../lib') +require 'hcl' + + diff --git a/test/utility_test.rb b/test/utility_test.rb index 1435d97..2de6c89 100644 --- a/test/utility_test.rb +++ b/test/utility_test.rb @@ -3,15 +3,15 @@ require 'test_helper' class UtilityTest < Test::Unit::TestCase include HCl::Utility - should "convert decimal input when converting time2float" do + def test_time2float_decimal assert_equal 2.5, time2float("2.5") end - should "convert HH:MM input when converting time2float" do + def test_time2float_hhmm assert_equal 2.5, time2float("2:30") end - should "assume decimal input when converting time2float" do + def test_time2float_assume_decimal assert_equal 2.0, time2float("2") end end |
