diff options
| author | Zack Hobson | 2013-11-21 12:02:47 -0800 | 
|---|---|---|
| committer | Zack Hobson | 2013-11-21 12:06:52 -0800 | 
| commit | 125133158e4d021526638789848b238ecd268f49 (patch) | |
| tree | 404e2c6db5e8f85d09943e22ed3f2fd7908faf5b | |
| parent | 86ff02c8380fc50cfa7e0d4e6d0cfd7be56fb633 (diff) | |
| download | hcl-125133158e4d021526638789848b238ecd268f49.tar.bz2 | |
Test and dev improvements
* removed dependency on shoulda
* added bundler support for dev/testing
* test coverage reporting
* added some command tests
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | CHANGELOG | 5 | ||||
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 33 | ||||
| -rw-r--r-- | hcl.gemspec | 2 | ||||
| -rw-r--r-- | lib/hcl/app.rb | 15 | ||||
| -rw-r--r-- | lib/hcl/commands.rb | 18 | ||||
| -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 | 
12 files changed, 155 insertions, 25 deletions
| @@ -6,3 +6,4 @@ doc  .rvmrc  .rvmrc.*  *.gem +coverage @@ -1,5 +1,10 @@  = Recent Changes in HCl +== v0.4.5 + +* allow filtering of tasks by project code +* eliminate shoulda from development dependencies +  == v0.4.4  * added completion command to output a Bash auto-complete script, closes #34 @@ -0,0 +1 @@ +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..92d5c29 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,33 @@ +PATH +  remote: . +  specs: +    hcl (0.4.4) +      chronic +      highline +      trollop + +GEM +  specs: +    chronic (0.9.1) +    highline (1.6.19) +    metaclass (0.0.1) +    mocha (0.14.0) +      metaclass (~> 0.0.1) +    multi_json (1.8.2) +    rubygems-tasks (0.2.4) +    simplecov (0.7.1) +      multi_json (~> 1.0) +      simplecov-html (~> 0.7.1) +    simplecov-html (0.7.1) +    trollop (2.0) +    yard (0.8.7.3) + +PLATFORMS +  ruby + +DEPENDENCIES +  hcl! +  mocha +  rubygems-tasks +  simplecov +  yard diff --git a/hcl.gemspec b/hcl.gemspec index 3bf1c4d..1e1232e 100644 --- a/hcl.gemspec +++ b/hcl.gemspec @@ -19,8 +19,8 @@ Gem::Specification.new do |s|    s.add_runtime_dependency 'chronic'    s.add_runtime_dependency 'highline'    s.add_development_dependency 'rubygems-tasks' -  s.add_development_dependency 'shoulda'    s.add_development_dependency 'mocha'    s.add_development_dependency 'yard' +  s.add_development_dependency 'simplecov'  end diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 684f521..c86e3c5 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -9,20 +9,23 @@ module HCl      include HCl::Utility      include HCl::Commands -    SETTINGS_FILE = "#{ENV['HOME']}/.hcl/settings.yml" -    CONFIG_FILE = "#{ENV['HOME']}/.hcl/config.yml" + +    HCL_DIR = ENV['HCL_DIR'] || "#{ENV['HOME']}/.hcl" +    SETTINGS_FILE = "#{HCL_DIR}/settings.yml" +    CONFIG_FILE = "#{HCL_DIR}/config.yml"      OLD_SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings"      OLD_CONFIG_FILE = "#{ENV['HOME']}/.hcl_config" -    def initialize +    def configure        FileUtils.mkdir_p(File.join(ENV['HOME'], ".hcl"))        read_config        read_settings +      self      end      # Run the given command and arguments.      def self.command *args -      hcl = new.process_args(*args).run +      new.configure.process_args(*args).run      end      # Return true if the string is a known command, false otherwise. @@ -47,10 +50,10 @@ module HCl                end              end            else -            start @command, *@args +            puts start(@command, *@args)            end          else -          show +          puts show          end        rescue RuntimeError => e          STDERR.puts "Error: #{e}" diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index 3d1b494..c245710 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -5,7 +5,10 @@ module HCl    module Commands      def tasks project_code=nil        tasks = Task.all -      DayEntry.all if tasks.empty? # cache tasks +      if tasks.empty? # cache tasks +        DayEntry.all +        tasks = Task.all +      end        tasks.select! {|t| t.project.code == project_code } if project_code        if tasks.empty?          puts "No matching tasks." @@ -52,14 +55,14 @@ module HCl      def unalias task        unset "task.#{task}" -        puts "Removed task alias @#{task}." +      "Removed task alias @#{task}."      end      def alias task_name, *value        task = Task.find *value        if task          set "task.#{task_name}", *value -        puts "Added alias @#{task_name} for #{task}." +        "Added alias @#{task_name} for #{task}."        else          puts "Unrecognized project and task ID: #{value.inspect}"          exit 1 @@ -84,7 +87,7 @@ module HCl        timer = task.start \          :starting_time => starting_time,          :note => args.join(' ') -      puts "Started timer for #{timer} (at #{current_time})" +      "Started timer for #{timer} (at #{current_time})"      end      def log *args @@ -119,14 +122,15 @@ module HCl      def show *args        date = args.empty? ? nil : Chronic.parse(args.join(' '))        total_hours = 0.0 +      result = ''        DayEntry.all(date).each do |day|          running = day.running? ? '(running) ' : ''          columns = HighLine::SystemExtensions.terminal_size[0] -        puts "\t#{day.formatted_hours}\t#{running}#{day.project}: #{day.notes.lines.last}"[0..columns-1] +        result << "\t#{day.formatted_hours}\t#{running}#{day.project}: #{day.notes.lines.last}\n"[0..columns-1]          total_hours = total_hours + day.hours.to_f        end -      puts "\t" + '-' * 13 -      puts "\t#{as_hours total_hours}\ttotal (as of #{current_time})" +      result << ("\t" + '-' * 13) << "\n" +      result << "\t#{as_hours total_hours}\ttotal (as of #{current_time})\n"      end      def resume *args 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 | 
