hub/test/standalone_test.rb

58 строки
1.4 KiB
Ruby
Исходник Обычный вид История

2009-12-09 04:52:23 +03:00
require 'helper'
require 'hub/standalone'
2009-12-09 06:06:45 +03:00
require 'fileutils'
require 'stringio'
2009-12-09 04:52:23 +03:00
class StandaloneTest < Minitest::Test
2009-12-09 06:06:45 +03:00
include FileUtils
def setup
rm "hub" if File.exist? 'hub'
rm_rf "/tmp/_hub_private" if File.exist? '/tmp/_hub_private'
2009-12-09 06:06:45 +03:00
mkdir "/tmp/_hub_private"
chmod 0400, "/tmp/_hub_private"
end
def teardown
rm "hub" if File.exist? 'hub'
rm_rf "/tmp/_hub_private" if File.exist? "/tmp/_hub_private"
2009-12-09 06:06:45 +03:00
end
2009-12-09 04:52:23 +03:00
def test_standalone
io = StringIO.new
Hub::Standalone.build io
standalone = io.string
assert_includes "This file is generated code", standalone
2009-12-09 04:52:23 +03:00
assert_includes "Runner", standalone
assert_includes "Args", standalone
assert_includes "Commands", standalone
assert_includes ".execute(*ARGV)", standalone
assert_not_includes "module Standalone", standalone
2009-12-09 23:10:31 +03:00
standalone =~ /__END__\s*(.+)/m
assert_equal File.read('man/hub.1'), $1
2009-12-09 04:52:23 +03:00
end
2009-12-09 06:06:45 +03:00
def test_standalone_save
2009-12-09 07:14:26 +03:00
Hub::Standalone.save("hub")
output = `RUBYOPT= RUBYLIB= ./hub version 2>&1`
assert_equal <<-OUT, output
git version 1.7.0.4
hub version #{Hub::VERSION}
OUT
2009-12-09 06:06:45 +03:00
end
def test_standalone_save_permission_denied
2009-12-09 07:14:26 +03:00
assert_raises Errno::EACCES do
Hub::Standalone.save("hub", "/tmp/_hub_private")
end
2009-12-09 06:06:45 +03:00
end
def test_standalone_save_doesnt_exist
2009-12-09 07:14:26 +03:00
assert_raises Errno::ENOENT do
Hub::Standalone.save("hub", "/tmp/something/not/real")
end
2009-12-09 06:06:45 +03:00
end
2009-12-09 04:52:23 +03:00
end