diff --git a/Gemfile b/Gemfile index 32e8b33..e041fbc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source "http://rubygems.org" gem "downlow", "~> 0.1.3" +gem "thor" gem "yajl-ruby" gem "version_sorter", "~> 1.1.0" gem "leftright" diff --git a/Gemfile.lock b/Gemfile.lock index eb2ad5b..ddf7e25 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,7 @@ GEM rake (0.8.7) rubyzip (0.9.4) shoulda (2.11.3) + thor (0.14.4) version_sorter (1.1.0) yajl-ruby (0.7.7) @@ -24,5 +25,6 @@ DEPENDENCIES leftright mocha shoulda + thor version_sorter (~> 1.1.0) yajl-ruby diff --git a/bin/jim b/bin/jim index 8ea5717..d53fc8e 100755 --- a/bin/jim +++ b/bin/jim @@ -2,5 +2,4 @@ require 'jim' -cli = Jim::CLI.new(ARGV) -cli.run \ No newline at end of file +Jim::CLI.start \ No newline at end of file diff --git a/lib/jim/cli.rb b/lib/jim/cli.rb index ef16e18..64597f7 100644 --- a/lib/jim/cli.rb +++ b/lib/jim/cli.rb @@ -143,7 +143,7 @@ def list(search = nil) logger.info "Installed:" print_version_list(list) end - alias :installed :list + map "installed" => "list" desc "available [SEARCH]" ,"List all available projects and versions including those in the local path, or paths specified in a Jimfile" def available(search = nil) @@ -176,7 +176,7 @@ def remove(name, version = nil) logger.info "No installed files matched." end end - alias :uninstall :remove + map "uninstall" => "remove" desc "resolve", "Resolve all the paths listed in a Jimfile and print them to STDOUT. If no Jimfile is set in the options, assumes ./Jimfile." def resolve diff --git a/test/helper.rb b/test/helper.rb index 7e897ee..2265c41 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -57,4 +57,19 @@ def assert_not_readable(*args) assert !File.readable?(full_path), "Expected #{full_path} to not be a readable file" end + # stolen from the thor specs + def capture(stream) + begin + stream = stream.to_s + eval "$#{stream} = StringIO.new" + yield + result = eval("$#{stream}").string + ensure + eval("$#{stream} = #{stream.upcase}") + end + + result + end + alias :silence :capture + end diff --git a/test/test_jim_cli.rb b/test/test_jim_cli.rb index 20d4ae9..9fea20b 100644 --- a/test/test_jim_cli.rb +++ b/test/test_jim_cli.rb @@ -20,9 +20,9 @@ class TestJimCLI < Test::Unit::TestCase context "pack" do should "run vendor, bundle, compress" do - Jim::CLI.any_instance.expects(:compress).once - Jim::Bundler.any_instance.stubs(:compress_js).returns("compressed.js") + Jim::Bundler.any_instance.expects(:compress_js).returns("compressed.js") run_cli("pack", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path) + puts `tree -r #{File.join(tmp_path, 'public', 'javascripts')}` assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'jquery-1.4.1.js' assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'myproject-1.2.2.js' assert_readable tmp_path, 'public', 'javascripts', 'bundled.js' @@ -79,7 +79,9 @@ class TestJimCLI < Test::Unit::TestCase end def run_cli(*args) - Jim::CLI.new(args.collect {|a| a.to_s }).run(true) + @stdout = capture(:stdout) do + Jim::CLI.start(args.collect(&:to_s)) + end end end