diff options
| author | Zack Hobson | 2013-12-10 15:30:13 -0800 | 
|---|---|---|
| committer | Zack Hobson | 2013-12-10 15:30:13 -0800 | 
| commit | c9d603a791e07e4e5b5dbd07cd7c5d1c27115d18 (patch) | |
| tree | 8728dd0b6b019c9940f2434d41fe7cf4c8e34d31 | |
| parent | 0d420ebc9d47d35ee2cf497f17a3b672b56537e0 (diff) | |
| download | hcl-c9d603a791e07e4e5b5dbd07cd7c5d1c27115d18.tar.bz2 | |
silence during testing!
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 3 | ||||
| -rw-r--r-- | lib/hcl/app.rb | 13 | ||||
| -rw-r--r-- | lib/hcl/commands.rb | 26 | ||||
| -rw-r--r-- | lib/hcl/utility.rb | 5 | ||||
| -rw-r--r-- | test/app_test.rb | 2 | ||||
| -rw-r--r-- | test/command_test.rb | 2 | ||||
| -rw-r--r-- | test/day_entry_test.rb | 2 | ||||
| -rw-r--r-- | test/task_test.rb | 2 | ||||
| -rw-r--r-- | test/test_helper.rb | 25 | ||||
| -rw-r--r-- | test/timesheet_resource_test.rb | 2 | ||||
| -rw-r--r-- | test/utility_test.rb | 2 | 
12 files changed, 49 insertions, 36 deletions
| @@ -4,7 +4,6 @@ gemspec  gem 'rubysl-abbrev', platform:'rbx'  gem 'rubysl-singleton', platform:'rbx'  gem 'rubysl-rexml', platform:'rbx' -gem 'rubysl-test-unit', platform:'rbx', group:'test'  gem 'rubysl-coverage', platform:'rbx', group:'test'  gem 'rubinius-coverage', platform:'rbx', group:'test'  gem 'yajl-ruby', platform:'rbx', group:'test' diff --git a/Gemfile.lock b/Gemfile.lock index 44ca467..cb0c813 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,8 +24,6 @@ GEM      rubysl-coverage (2.0.3)      rubysl-rexml (2.0.2)      rubysl-singleton (2.0.0) -    rubysl-test-unit (2.0.3) -      minitest (~> 4.7)      simplecov (0.7.1)        multi_json (~> 1.0)        simplecov-html (~> 0.7.1) @@ -50,7 +48,6 @@ DEPENDENCIES    rubysl-coverage    rubysl-rexml    rubysl-singleton -  rubysl-test-unit    simplecov    yajl-ruby    yard diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 9c176af..f164ff5 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -55,22 +55,25 @@ module HCl          else            puts show          end +      rescue CommandError => e +        $stderr.puts e +        exit 1        rescue RuntimeError => e -        STDERR.puts "Error: #{e}" +        $stderr.puts "Error: #{e}"          exit 1        rescue SocketError => e -        STDERR.puts "Connection failed. (#{e.message})" +        $stderr.puts "Connection failed. (#{e.message})"          exit 1        rescue TimesheetResource::ThrottleFailure => e -        STDERR.puts "Too many requests, retrying in #{e.retry_after+5} seconds..." +        $stderr.puts "Too many requests, retrying in #{e.retry_after+5} seconds..."          sleep e.retry_after+5          run        rescue TimesheetResource::AuthFailure => e -        STDERR.puts "Unable to authenticate: #{e}" +        $stderr.puts "Unable to authenticate: #{e}"          request_config          run        rescue TimesheetResource::Failure => e -        STDERR.puts "API failure: #{e}" +        $stderr.puts "API failure: #{e}"          exit 1        end      end diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index 9bd5271..da3b1f0 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -3,6 +3,8 @@ require 'highline'  module HCl    module Commands +    class Error < StandardError; end +      def tasks project_code=nil        tasks = Task.all        if tasks.empty? # cache tasks @@ -11,8 +13,7 @@ module HCl        end        tasks.select! {|t| t.project.code == project_code } if project_code        if tasks.empty? -        puts "No matching tasks." -        exit 1 +        fail "No matching tasks."        end        tasks.map { |task| "#{task.project.id} #{task.id}\t#{task}" }.join("\n")      end @@ -37,12 +38,10 @@ module HCl          if entry.cancel            "Deleted entry #{entry}."          else -          puts "Failed to delete #{entry}!" -          exit 1 +          fail "Failed to delete #{entry}!"          end        else -        puts 'Nothing to cancel.' -        exit 1 +        fail 'Nothing to cancel.'        end      end      alias_method :oops, :cancel @@ -64,8 +63,7 @@ module HCl          set "task.#{task_name}", *value          "Added alias @#{task_name} for #{task}."        else -        puts "Unrecognized project and task ID: #{value.inspect}" -        exit 1 +        fail "Unrecognized project and task ID: #{value.inspect}"        end      end @@ -81,8 +79,7 @@ module HCl        starting_time = get_starting_time args        task = get_task args        if task.nil? -        puts "Unknown task alias, try one of the following: ", aliases.join(', ') -        exit 1 +        fail "Unknown task alias, try one of the following: ", aliases.join(', ')        end        timer = task.start \          :starting_time => starting_time, @@ -102,8 +99,7 @@ module HCl          entry.toggle          "Stopped #{entry} (at #{current_time})"        else -        puts "No running timers found." -        exit 1 +        fail "No running timers found."        end      end @@ -117,8 +113,7 @@ module HCl            "Added note to #{entry}."          end        else -        puts "No running timers found." -        exit 1 +        fail "No running timers found."        end      end @@ -147,8 +142,7 @@ module HCl        if entry          entry.toggle        else -        puts "No matching timer found." -        exit 1 +        fail "No matching timer found."        end      end diff --git a/lib/hcl/utility.rb b/lib/hcl/utility.rb index 8026069..72b4842 100644 --- a/lib/hcl/utility.rb +++ b/lib/hcl/utility.rb @@ -1,5 +1,10 @@  module HCl +  class CommandError < StandardError; end    module Utility +    def fail message +      raise CommandError, message +    end +      def get_task_ids ident, args        if @settings.key? "task.#{ident}"          @settings["task.#{ident}"].split(/\s+/) diff --git a/test/app_test.rb b/test/app_test.rb index c533076..c9496c0 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -1,5 +1,5 @@  require 'test_helper' -class AppTest < MiniTest::Unit::TestCase +class AppTest < HCl::TestCase    def setup      # touch config to avoid triggering manual config diff --git a/test/command_test.rb b/test/command_test.rb index 61d9f22..b554bfd 100644 --- a/test/command_test.rb +++ b/test/command_test.rb @@ -1,5 +1,5 @@  require 'test_helper' -class CommandTest < MiniTest::Unit::TestCase +class CommandTest < HCl::TestCase    include HCl::Commands    include HCl::Utility diff --git a/test/day_entry_test.rb b/test/day_entry_test.rb index 8b68348..5b390c3 100644 --- a/test/day_entry_test.rb +++ b/test/day_entry_test.rb @@ -1,6 +1,6 @@  require 'test_helper' -class DayEntryTest < MiniTest::Unit::TestCase +class DayEntryTest < HCl::TestCase    def test_from_xml      entries = HCl::DayEntry.from_xml(<<-EOD)  <daily> diff --git a/test/task_test.rb b/test/task_test.rb index ecffdb5..e313f73 100644 --- a/test/task_test.rb +++ b/test/task_test.rb @@ -1,5 +1,5 @@ -class Task < MiniTest::Unit::TestCase +class Task < HCl::TestCase    def test_cache_file      assert_equal "#{HCl::App::HCL_DIR}/cache/tasks.yml", HCl::Task.cache_file    end diff --git a/test/test_helper.rb b/test/test_helper.rb index a09f25e..2fe445e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,21 +12,36 @@ begin      minimum_coverage case RUBY_ENGINE        when "rbx" then 84        when "jruby" then 73 -      else 77 +      else 78      end    end  rescue LoadError => e    $stderr.puts 'No test coverage tools found, skipping coverage check.'  end +# override the default hcl dir +ENV['HCL_DIR'] = File.dirname(__FILE__)+"/dot_hcl" +require 'hcl' +  require 'minitest/autorun'  require 'mocha/setup'  require 'fileutils'  require 'fakeweb' -# override the default hcl dir -ENV['HCL_DIR'] = File.dirname(__FILE__)+"/dot_hcl" - -require 'hcl' +module IgnoreStderr +  def before_setup +    super +    $stderr = @stderr = StringIO.new +    $stdout = @stdout = StringIO.new +  end +  def after_teardown +    super +    $stderr = STDERR +    $stdout = STDOUT +  end +end +class HCl::TestCase < MiniTest::Unit::TestCase +  include IgnoreStderr +end diff --git a/test/timesheet_resource_test.rb b/test/timesheet_resource_test.rb index 0ef6da1..4153429 100644 --- a/test/timesheet_resource_test.rb +++ b/test/timesheet_resource_test.rb @@ -1,6 +1,6 @@  require 'test_helper' -class TimesheetResourceTest < MiniTest::Unit::TestCase +class TimesheetResourceTest < HCl::TestCase    def setup      FakeWeb.allow_net_connect = false diff --git a/test/utility_test.rb b/test/utility_test.rb index f0652a0..adc55b6 100644 --- a/test/utility_test.rb +++ b/test/utility_test.rb @@ -1,6 +1,6 @@  require 'test_helper' -class UtilityTest < MiniTest::Unit::TestCase +class UtilityTest < HCl::TestCase    include HCl::Utility    def test_time2float_decimal | 
