Skip to content

Commit

Permalink
Moar Thor - better tests, fixed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
quirkey committed Nov 12, 2010
1 parent 43197ff commit 47d2675
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions 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"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)

Expand All @@ -24,5 +25,6 @@ DEPENDENCIES
leftright
mocha
shoulda
thor
version_sorter (~> 1.1.0)
yajl-ruby
3 changes: 1 addition & 2 deletions bin/jim
Expand Up @@ -2,5 +2,4 @@

require 'jim'

cli = Jim::CLI.new(ARGV)
cli.run
Jim::CLI.start
4 changes: 2 additions & 2 deletions lib/jim/cli.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/helper.rb
Expand Up @@ -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
8 changes: 5 additions & 3 deletions test/test_jim_cli.rb
Expand Up @@ -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'
Expand Down Expand Up @@ -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

0 comments on commit 47d2675

Please sign in to comment.