sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 8d025c1047bd313b4b09d9f7b328c9ae42ed0151
parent 119bc0fe037ff383cf5c7f5b6767640bbb12e217
Author: Whyme.Lyu <callme5long@gmail.com>
Date:   Fri, 17 May 2013 07:12:11 -0700

Merge pull request #50 from 5long/expand-tilde-in-source-url

Expand tilde in source url
Diffstat:
M Rakefile | 3 ++-
M bin/sup-config | 15 +++++++++------
A lib/sup/util/path.rb | 9 +++++++++
A lib/sup/util/uri.rb | 15 +++++++++++++++
M sup.gemspec | 1 +
M test/test_header_parsing.rb | 8 ++++----
A test/test_helper.rb | 1 +
M test/test_message.rb | 18 +++++-------------
M test/test_yaml_regressions.rb | 4 ++--
A test/unit/util/uri.rb | 19 +++++++++++++++++++
10 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/Rakefile b/Rakefile
@@ -3,9 +3,10 @@ require 'rake/testtask'
 
 Rake::TestTask.new(:test) do |test|
   test.libs << 'test'
-  test.test_files = FileList.new('test/test_*.rb')
+  test.test_files = FileList.new('test/**/test_*.rb')
   test.verbose = true
 end
+task :default => :test
 
 require 'rubygems/package_task'
 # For those who don't have `rubygems-bundler` installed
diff --git a/bin/sup-config b/bin/sup-config
@@ -19,11 +19,12 @@ EOS
 end
 
 def axe q, default=nil
-  ans = if default && !default.empty?
-    ask "#{q} (enter for \"#{default}\"): "
-  else
-    ask "#{q}: "
-  end
+  question = if default && !default.empty?
+               "#{q} (enter for \"#{default}\"): "
+             else
+               "#{q}: "
+             end
+  ans = ask question
   ans.empty? ? default : ans.to_s
 end
 
@@ -36,6 +37,8 @@ def build_cmd cmd
 end
 
 def add_source
+  require "sup/util/uri"
+
   type = nil
 
   say "Ok, adding a new source."
@@ -69,7 +72,7 @@ def add_source
     end
 
     uri = begin
-      URI::Generic.build components
+      Redwood::Util::Uri.build components
     rescue URI::Error => e
       say "Whoopsie! I couldn't build a URI from that: #{e.message}"
       if axe_yes("Try again?") then next else return end
diff --git a/lib/sup/util/path.rb b/lib/sup/util/path.rb
@@ -0,0 +1,9 @@
+module Redwood
+  module Util
+    module Path
+      def self.expand(path)
+        ::File.expand_path(path)
+      end
+    end
+  end
+end
diff --git a/lib/sup/util/uri.rb b/lib/sup/util/uri.rb
@@ -0,0 +1,15 @@
+require "uri"
+
+require "sup/util/path"
+
+module Redwood
+  module Util
+    module Uri
+      def self.build(components)
+        components = components.dup
+        components[:path] = Path.expand(components[:path])
+        ::URI::Generic.build(components)
+      end
+    end
+  end
+end
diff --git a/sup.gemspec b/sup.gemspec
@@ -47,5 +47,6 @@ DESC
 
     s.add_development_dependency "bundler", "~> 1.3"
     s.add_development_dependency "rake"
+    s.add_development_dependency "minitest", "~> 4"
   end
 end
diff --git a/test/test_header_parsing.rb b/test/test_header_parsing.rb
@@ -1,12 +1,12 @@
 #!/usr/bin/ruby
 
-require 'test/unit'
+require 'test_helper'
 require 'sup'
 require 'stringio'
 
 include Redwood
 
-class TestMBoxParsing < Test::Unit::TestCase
+class TestMBoxParsing < Minitest::Unit::TestCase
 
   def setup
     @path = Dir.mktmpdir
@@ -150,10 +150,10 @@ To: a dear friend
 Hello again! Would you like to buy my products?
 EOS
     offset = l.next_offset 0
-    assert_not_nil offset
+    refute_nil offset
 
     offset = l.next_offset offset
-    assert_not_nil offset
+    refute_nil offset
 
     offset = l.next_offset offset
     assert_nil offset
diff --git a/test/test_helper.rb b/test/test_helper.rb
@@ -0,0 +1 @@
+require 'minitest/autorun'
diff --git a/test/test_message.rb b/test/test_message.rb
@@ -1,6 +1,6 @@
 #!/usr/bin/ruby
 
-require 'test/unit'
+require 'test_helper'
 require 'sup'
 require 'stringio'
 
@@ -26,7 +26,7 @@ end
 
 module Redwood
 
-class TestMessage < Test::Unit::TestCase
+class TestMessage < ::Minitest::Unit::TestCase
 
   def setup
     @path = Dir.mktmpdir
@@ -289,7 +289,7 @@ EOS
     from = sup_message.from
     # very basic email address check
     assert_match(/\w+@\w+\.\w{2,4}/, from.email)
-    assert_not_nil(from.name)
+    refute_nil(from.name)
 
   end
 
@@ -327,11 +327,7 @@ EOS
 
     # read the message body chunks: no errors should reach this level
 
-    chunks = nil
-
-    assert_nothing_raised() do
-      chunks = sup_message.load_from_source!
-    end
+    chunks = sup_message.load_from_source!
 
     # the chunks list should be empty
 
@@ -426,10 +422,7 @@ EOS
 
     # read the message body chunks
 
-    assert_nothing_raised() do
-      chunks = sup_message.load_from_source!
-    end
-
+    sup_message.load_from_source!
   end
 
   def test_blank_header_lines
@@ -537,4 +530,3 @@ end
 end
 
 # vim:noai:ts=2:sw=2:
-
diff --git a/test/test_yaml_regressions.rb b/test/test_yaml_regressions.rb
@@ -1,4 +1,4 @@
-require 'test/unit'
+require 'test_helper'
 
 # Requiring 'yaml' before 'sup' in 1.9.x would get Psych loaded first
 # and becoming the default yamler.
@@ -6,7 +6,7 @@ require 'yaml'
 require 'sup'
 
 module Redwood
-  class TestYamlRegressions < Test::Unit::TestCase
+  class TestYamlRegressions < ::Minitest::Unit::TestCase
     def test_yamling_hash
       hsh = {:foo => 42}
       reloaded = YAML.load(hsh.to_yaml)
diff --git a/test/unit/util/uri.rb b/test/unit/util/uri.rb
@@ -0,0 +1,19 @@
+require "test_helper.rb"
+
+require "sup/util/uri"
+
+describe Redwood::Util::Uri do
+  describe ".build" do
+    it "builds uri from hash" do
+      components = {:path => "/var/mail/foo", :scheme => "mbox"}
+      uri = Redwood::Util::Uri.build(components)
+      uri.to_s.must_equal "mbox:/var/mail/foo"
+    end
+
+    it "expands ~ in path" do
+      components = {:path => "~/foo", :scheme => "maildir"}
+      uri = Redwood::Util::Uri.build(components)
+      uri.to_s.must_equal "maildir:#{ENV["HOME"]}/foo"
+    end
+  end
+end