class TestGemCodesearch

Public Instance Methods

setup() click to toggle source
# File test/test_all.rb, line 17
def setup
  @workdir = Dir.mktmpdir('gem-codesearch')
  ENV['MILKODE_DEFAULT_DIR'] = "#{@workdir}/milkode"
end
start_gem_server() { |pid, url| ... } click to toggle source
# File test/test_all.rb, line 29
def start_gem_server
  # "gem server" serves gem files already installed.
  gem_server_command = [GEM_COMMAND, 'server', '-b', '127.0.0.1', '-p', '0']
  pid = nil
  PTY.open {|m, s|
    s.raw!
    pid = spawn(*gem_server_command, :out => s, :err => IO::NULL)
    line = m.gets
    unless %r{Server started at (http:\S+)} =~ line
      flunk "unexpected 'gem server' message: #{line.inspect}"
    end
    url = $1
    yield [pid, url]
  }
ensure
  if pid
    Process.kill :TERM, pid
    Process.wait pid
  end
end
teardown() click to toggle source
# File test/test_all.rb, line 64
def teardown
  FileUtils.rmtree @workdir
  ENV['MILKODE_DEFAULT_DIR'] = nil
  ENV['GEM_CODESEARCH_URL'] = nil
  ENV['GEM_CODESEARCH_DIR'] = nil
end
test_all() click to toggle source
# File test/test_all.rb, line 54
def test_all
  start_gem_server {|pid, url|
    ENV['GEM_CODESEARCH_URL'] = url
    ENV['GEM_CODESEARCH_DIR'] = @workdir
    system(MILK_COMMAND, 'init', '--default', :out => IO::NULL)
    system(RAKE_COMMAND, '-f', RAKEFILE, 'all', [:out, :err] => IO::NULL)
    system(RAKE_COMMAND, '-f', RAKEFILE, 'all', [:out, :err] => IO::NULL) # update exisiting index.
  }
end
test_gem_server() click to toggle source
# File test/test_all.rb, line 50
def test_gem_server
  start_gem_server {|pid, url| }
end
test_milk_init() click to toggle source
# File test/test_all.rb, line 22
def test_milk_init
  assert(!File.exist?("#{@workdir}/milkode"))
  system(MILK_COMMAND, 'init', '--default', :out => IO::NULL)
  assert($?.success?)
  assert(File.exist?("#{@workdir}/milkode"))
end
test_setup_help() click to toggle source
# File test/test_bin.rb, line 10
def test_setup_help
  command = [RUBY_COMMAND, GEM_CODESEARCH_SETUP_COMMAND, 'help']
  message = IO.popen(command) {|io|
    io.read
  }
  assert_match(/rake help/, message)
  assert_match(/rake all/, message)
end