diff options
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | hcl.gemspec | 1 | ||||
| -rw-r--r-- | test/command_test.rb | 14 | ||||
| -rw-r--r-- | test/test_helper.rb | 1 | ||||
| -rw-r--r-- | test/timesheet_resource_test.rb | 38 |
5 files changed, 56 insertions, 0 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 9d443b9..abd966c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,6 +10,7 @@ GEM remote: https://rubygems.org/ specs: chronic (0.9.1) + fakeweb (1.3.0) highline (1.6.19) metaclass (0.0.1) mocha (0.14.0) @@ -27,6 +28,7 @@ PLATFORMS ruby DEPENDENCIES + fakeweb hcl! mocha rubygems-tasks diff --git a/hcl.gemspec b/hcl.gemspec index 1e1232e..06206a3 100644 --- a/hcl.gemspec +++ b/hcl.gemspec @@ -22,5 +22,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'mocha' s.add_development_dependency 'yard' s.add_development_dependency 'simplecov' + s.add_development_dependency 'fakeweb' end diff --git a/test/command_test.rb b/test/command_test.rb index 5a2e003..b425974 100644 --- a/test/command_test.rb +++ b/test/command_test.rb @@ -82,6 +82,14 @@ class CommandTest < Test::Unit::TestCase resume end + def test_resume_with_task_alias + entry = stub + expects(:get_task_ids).with('mytask',[]).returns(%w[ 456 789 ]) + HCl::DayEntry.expects(:last_by_task).with('456', '789').returns(entry) + entry.expects(:toggle) + resume 'mytask' + end + def test_cancel entry = stub HCl::DayEntry.expects(:with_timer).returns(entry) @@ -96,4 +104,10 @@ class CommandTest < Test::Unit::TestCase note 'hi world' end + def test_note_display + entry = stub(notes:"your face") + HCl::DayEntry.expects(:with_timer).returns(entry) + assert_equal "your face", note + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 978920a..8b4f7a0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,6 +10,7 @@ end require 'test/unit' require 'mocha/setup' require 'fileutils' +require 'fakeweb' # override the default hcl dir FileUtils.mkdir_p __dir__+"/dot_hcl" diff --git a/test/timesheet_resource_test.rb b/test/timesheet_resource_test.rb new file mode 100644 index 0000000..93977f9 --- /dev/null +++ b/test/timesheet_resource_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class TimesheetResourceTest < Test::Unit::TestCase + + def setup + FakeWeb.allow_net_connect = false + HCl::TimesheetResource.configure \ + 'login' => 'bob', + 'password' => 'secret', + 'subdomain' => 'bobclock', + 'ssl' => true + end + + def test_configure + assert_equal 'bob', HCl::TimesheetResource.login + assert_equal 'secret', HCl::TimesheetResource.password + assert_equal 'bobclock', HCl::TimesheetResource.subdomain + assert_equal true, HCl::TimesheetResource.ssl + end + + def test_http_get + FakeWeb.register_uri(:get, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'gotten!') + body = HCl::TimesheetResource.get 'foo' + assert_equal 'gotten!', body + end + + def test_http_post + FakeWeb.register_uri(:post, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'posted!') + body = HCl::TimesheetResource.post 'foo', {pizza:'taco'} + assert_equal 'posted!', body + end + + def test_http_delete + FakeWeb.register_uri(:delete, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'wiped!') + body = HCl::TimesheetResource.delete 'foo' + assert_equal 'wiped!', body + end +end |
