提交 8dd8afaf 编写于 作者: M Mislav Marohnić

bootstrap Cucumber test suite with Aruba

上级 b4c5ea0b
......@@ -2,3 +2,4 @@
*~
/hub
Gemfile.lock
tmp/
source 'https://rubygems.org'
gem 'ronn', :group => :development
gem 'ronn'
gem 'aruba'
gem 'cucumber'
gemspec
......@@ -27,7 +27,7 @@ end
# Tests
#
task :default => :test
task :default => [:test, :features]
Rake::TestTask.new do |t|
t.libs << 'test'
......@@ -36,6 +36,10 @@ Rake::TestTask.new do |t|
t.verbose = false
end
task :features do
sh 'RUBYLIB=lib cucumber -f progress -t ~@wip features'
end
#
# Manual
#
......
require 'aruba/cucumber'
require 'fileutils'
require 'hub/context'
unless system_git = Hub::Context.which('git')
abort "Error: `git` not found in PATH"
end
lib_dir = File.expand_path('../../../lib', __FILE__)
bin_dir = File.expand_path('../fakebin', __FILE__)
Before do
# don't want hub to run in bundle
unset_bundler_env_vars
# have bin/hub load code from the current project
set_env 'RUBYLIB', lib_dir
# put fakebin on the PATH
set_env 'PATH', "#{bin_dir}:#{ENV['PATH']}"
# exclude this project's git directory from use in testing
set_env 'GIT_CEILING_DIRECTORIES', File.dirname(lib_dir)
# sabotage git commands that might try to access a remote host
set_env 'GIT_PROXY_COMMAND', 'echo'
# avoids reading from current user's "~/.gitconfig"
set_env 'HOME', File.expand_path(File.join(current_dir, 'home'))
# used in fakebin/git
set_env 'HUB_SYSTEM_GIT', system_git
FileUtils.mkdir_p ENV['HOME']
end
Before '~@noexec' do
set_env 'GIT', nil
end
Before '@noexec' do
set_env 'GIT', 'echo'
end
World Module.new {
def history
histfile = File.join(ENV['HOME'], '.history')
if File.exist? histfile
File.readlines histfile
else
[]
end
end
def assert_command_run cmd
cmd += "\n" unless cmd[-1..-1] == "\n"
history.should include(cmd)
end
def edit_hub_config
config = File.join(ENV['HOME'], '.config/hub')
FileUtils.mkdir_p File.dirname(config)
if File.exist? config
data = YAML.load File.read(config)
else
data = {}
end
yield data
File.open(config, 'w') { |cfg| cfg << YAML.dump(data) }
end
def run_silent cmd
in_current_dir do
output = `#{cmd} 2>&1`.chomp
$?.should be_success
output
end
end
}
#!/bin/sh
# A wrapper for system git that prevents commands such as `clone` or `fetch` to be
# executed in testing. It logs commands to "~/.history" so afterwards it can be
# asserted that they ran.
command="$1"
[ "$command" == "config" ] || echo git "$@" >> "$HOME"/.history
case "$command" in
"clone" | "fetch" | "pull" | "push" )
exit
;;
* )
[ "$command $2 $3" == "remote add -f" ] && exit
# note: `submodule add` also initiates a clone, but we work around it
;;
esac
exec "$HUB_SYSTEM_GIT" "$@"
......@@ -409,50 +409,55 @@ module Hub
editor.shellsplit
end
# Cross-platform web browser command; respects the value set in $BROWSER.
#
# Returns an array, e.g.: ['open']
def browser_launcher
browser = ENV['BROWSER'] || (
osx? ? 'open' : windows? ? 'start' :
%w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
)
abort "Please set $BROWSER to a web launcher to use this command." unless browser
Array(browser)
end
def osx?
require 'rbconfig'
RbConfig::CONFIG['host_os'].to_s.include?('darwin')
end
def windows?
require 'rbconfig'
RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/
end
module System
# Cross-platform web browser command; respects the value set in $BROWSER.
#
# Returns an array, e.g.: ['open']
def browser_launcher
browser = ENV['BROWSER'] || (
osx? ? 'open' : windows? ? 'start' :
%w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
)
abort "Please set $BROWSER to a web launcher to use this command." unless browser
Array(browser)
end
def osx?
require 'rbconfig'
RbConfig::CONFIG['host_os'].to_s.include?('darwin')
end
def windows?
require 'rbconfig'
RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/
end
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
}
end
return nil
end
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
}
# Checks whether a command exists on this system in the $PATH.
#
# name - The String name of the command to check for.
#
# Returns a Boolean.
def command?(name)
!which(name).nil?
end
return nil
end
# Checks whether a command exists on this system in the $PATH.
#
# name - The String name of the command to check for.
#
# Returns a Boolean.
def command?(name)
!which(name).nil?
end
include System
extend System
end
end
......@@ -22,7 +22,7 @@ class HubTest < Test::Unit::TestCase
COMMANDS = []
Hub::Context.class_eval do
Hub::Context::System.class_eval do
remove_method :which
define_method :which do |name|
COMMANDS.include?(name) ? "/usr/bin/#{name}" : nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册