Skip to content

Commit

Permalink
Merge branch 'minor'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Jul 17, 2014
2 parents db67a66 + 4ca8305 commit 0a03b80
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 51 deletions.
17 changes: 2 additions & 15 deletions bin/tork
Expand Up @@ -46,29 +46,15 @@ This program can be controlled remotely by multiple tork-remote(1) instances.
## FILES
*.tork/config.rb*
Optional Ruby script that is loaded inside the driver process on startup.
Optional Ruby script that is loaded inside this Tork process on startup.
It can read and change the `ENV['TORK_CONFIGS']` environment variable.
## ENVIRONMENT
`TORK_CONFIGS`
Colon-separated (:) list of either paths to directories that contain
configuration files or names of the following configuration helpers.
If this variable is not set, then its value is assumed to be "default".
> `default`
> Loads the following configuration helpers (as appropriate) if your
> current working directory appears to utilize what they configure.
> See below for complete descriptions of these configuration helpers.
>
> * bundler
> * rails
> * devise
> * test
> * spec
> * cucumber
> * factory_girl
>
> `dotlog`
> Hides log files by prefixing their names with a period (dot).
>
Expand Down Expand Up @@ -129,6 +115,7 @@ tork-runner(1), tork-driver(1), tork-master(1)
=end =========================================================================

TORK_DOLLAR_ZERO = $0
$0 = File.basename(__FILE__) # for easier identification in ps(1) output

require 'binman'
Expand Down
2 changes: 1 addition & 1 deletion bin/tork-driver
Expand Up @@ -51,7 +51,7 @@ to stdout.
## FILES
*.tork/config.rb*
Optional Ruby script that is loaded inside the driver process on startup.
Optional Ruby script that is loaded inside this Tork process on startup.
It can read and change the `ENV['TORK_CONFIGS']` environment variable.
`.tork/driver.rb`
Expand Down
2 changes: 1 addition & 1 deletion bin/tork-engine
Expand Up @@ -76,7 +76,7 @@ to stdout.
## FILES
*.tork/config.rb*
Optional Ruby script that is loaded inside the driver process on startup.
Optional Ruby script that is loaded inside this Tork process on startup.
It can read and change the `ENV['TORK_CONFIGS']` environment variable.
*.tork/engine.rb*
Expand Down
2 changes: 1 addition & 1 deletion bin/tork-master
Expand Up @@ -66,7 +66,7 @@ to stdout.
## FILES
*.tork/config.rb*
Optional Ruby script that is loaded inside the driver process on startup.
Optional Ruby script that is loaded inside this Tork process on startup.
It can read and change the `ENV['TORK_CONFIGS']` environment variable.
*.tork/master.rb*
Expand Down
11 changes: 10 additions & 1 deletion lib/tork/cliapp.rb
Expand Up @@ -18,6 +18,10 @@ def join client
help client
end

BACKTRACE_CENSOR = /\n\s+(?:from\s)?#{
Regexp.union(File.expand_path('../../..', __FILE__), TORK_DOLLAR_ZERO)
}[^:]*:\d+:.+$/

def recv client, message
case client
when @driver
Expand All @@ -40,7 +44,12 @@ def recv client, message
when :fail then "\e[31m%s\e[0m" # red
end
message = color % message if color and STDOUT.tty?
message = [message, File.read(log_file), message] if event_sym == :fail

if event_sym == :fail
# censor Tork internals from test failure backtraces
log = File.read(log_file).gsub(BACKTRACE_CENSOR, '')
message = [message, log, message]
end

tell @clients, message, false
end
Expand Down
10 changes: 5 additions & 5 deletions lib/tork/config.rb
@@ -1,17 +1,17 @@
module Tork
# Loads all Ruby scripts found having the given name in (1) the directories
# specified in the TORK_CONFIGS environment variable, (2) the subdirectories
# specified in the given $TORK_CONFIGS search path, (2) the subdirectories
# of lib/tork/config/, and (3) the user's .tork/ directory; in that order.
#
# @return [Array] paths of Ruby scripts that were loaded
#
def self.config name
dirs = ENV['TORK_CONFIGS'].strip.split(/:+/).reject(&:empty?).uniq.
def self.config name, search_path=ENV['TORK_CONFIGS']
dirs = search_path.to_s.strip.split(/:+/).reject(&:empty?).uniq.
map {|dir| [dir, __FILE__.sub(/\.rb$/, "/#{dir}")] }.flatten

Dir["{#{dirs.join(',')},.tork}/#{name}.rb"].each {|script| load script }
end
end

ENV['TORK_CONFIGS'] ||= 'default'.freeze # ENV values come frozen by default
Tork.config :config
ENV['TORK_CONFIGS'] ||= String.new.freeze # ENV values come frozen by default
Tork.config :config, '*'
1 change: 1 addition & 0 deletions lib/tork/config/bundler/config.rb
@@ -0,0 +1 @@
ENV['TORK_CONFIGS'] += ':bundler' if Dir['Gemfile{,.lock}'].any?
1 change: 1 addition & 0 deletions lib/tork/config/cucumber/config.rb
@@ -0,0 +1 @@
ENV['TORK_CONFIGS'] += ':cucumber' if File.directory? 'features'
7 changes: 0 additions & 7 deletions lib/tork/config/default/config.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/tork/config/devise/config.rb
@@ -0,0 +1 @@
ENV['TORK_CONFIGS'] += ':devise' if File.exist? 'config/initializers/devise.rb'
1 change: 1 addition & 0 deletions lib/tork/config/factory_girl/config.rb
@@ -0,0 +1 @@
ENV['TORK_CONFIGS'] += ':factory_girl' if Dir['{test,spec}/factories/'].any?
1 change: 1 addition & 0 deletions lib/tork/config/rails/config.rb
@@ -0,0 +1 @@
ENV['TORK_CONFIGS'] += ':rails' if Dir['script/{rails,console}'].any?
4 changes: 4 additions & 0 deletions lib/tork/config/spec/config.rb
@@ -0,0 +1,4 @@
$tork_config_spec_glob = '**/{spec_*,*_spec}.rb'
$tork_config_spec_grep = %r{.*(\bspec_[^/]+|[^/]+_spec)\.rb$}

ENV['TORK_CONFIGS'] += ':spec' if Dir['spec/', $tork_config_spec_glob].any?
14 changes: 5 additions & 9 deletions lib/tork/config/spec/driver.rb
@@ -1,17 +1,13 @@
Tork::Driver::REABSORB_FILE_GREPS.push 'spec/spec_helper.rb'
Tork::Driver::REABSORB_FILE_GREPS.push /\bspec_helper\.rb$/

Tork::Driver::ALL_TEST_FILE_GLOBS.push 'spec/**/{spec_*,*_spec}.rb'
Tork::Driver::ALL_TEST_FILE_GLOBS.push $tork_config_spec_glob

Tork::Driver::TEST_FILE_GLOBBERS.update(
# source files that correspond to test files
%r{^lib/.*?([^/]+)\.rb$} => lambda do |matches|
target = matches[1]
"spec/**/{spec_#{target},#{target}_spec}.rb"
%r{([^/]+)\.rb$} => lambda do |matches|
$tork_config_spec_glob.gsub(/(?<=_)\*|\*(?=_)/, matches[1])
end,

# the actual test files themselves
%r{^spec/.+\.rb$} => lambda do |matches|
target = matches[0]
target if File.basename(target) =~ /^spec_|_spec\./
end
$tork_config_spec_grep => lambda {|matches| matches[0] }
)
1 change: 1 addition & 0 deletions lib/tork/config/spec/master.rb
@@ -1,4 +1,5 @@
$LOAD_PATH.unshift 'spec' unless $LOAD_PATH.include? 'spec'
$LOAD_PATH.unshift 'lib' unless $LOAD_PATH.include? 'lib'
require 'spec_helper' if File.exist? 'spec/spec_helper.rb'
require './spec_helper' if File.exist? 'spec_helper.rb'
require 'rspec/autorun' if defined? RSpec
2 changes: 1 addition & 1 deletion lib/tork/config/spec/worker.rb
Expand Up @@ -5,7 +5,7 @@
# ignore
end

if $tork_test_file.start_with? 'spec/' and $tork_line_numbers.any?
if $tork_line_numbers.any? and $tork_test_file =~ $tork_config_spec_grep
if rspec_version and rspec_version >= '3.0'
ARGV.push [$tork_test_file, *$tork_line_numbers].join(':')
else
Expand Down
10 changes: 10 additions & 0 deletions lib/tork/config/test/config.rb
@@ -0,0 +1,10 @@
# people generally prefix or suffix their test file names with these labels
# https://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing#Naming_Conventions
labels = %w[ test ts tc t ]
labels_glob = '{' + labels.join(',') + '}'
labels_grep = '(' + labels.join('|') + ')'

$tork_config_test_glob = "**/{#{labels_glob}_*,*_#{labels_glob}}.rb"
$tork_config_test_grep = %r{.*(\b#{labels_grep}_[^/]+|[^/]+_#{labels_grep})\.rb$}

ENV['TORK_CONFIGS'] += ':test' if Dir['test/', $tork_config_test_glob].any?
14 changes: 5 additions & 9 deletions lib/tork/config/test/driver.rb
@@ -1,17 +1,13 @@
Tork::Driver::REABSORB_FILE_GREPS.push 'test/test_helper.rb'
Tork::Driver::REABSORB_FILE_GREPS.push /\btest_helper\.rb$/

Tork::Driver::ALL_TEST_FILE_GLOBS.push 'test/**/{test_*,*_test}.rb'
Tork::Driver::ALL_TEST_FILE_GLOBS.push $tork_config_test_glob

Tork::Driver::TEST_FILE_GLOBBERS.update(
# source files that correspond to test files
%r{^lib/.*?([^/]+)\.rb$} => lambda do |matches|
target = matches[1]
"test/**/{test_#{target},#{target}_test}.rb"
%r{([^/]+)\.rb$} => lambda do |matches|
$tork_config_test_glob.gsub(/(?<=_)\*|\*(?=_)/, matches[1])
end,

# the actual test files themselves
%r{^test/.+\.rb$} => lambda do |matches|
target = matches[0]
target if File.basename(target) =~ /^test_|_test\./
end
$tork_config_test_grep => lambda {|matches| matches[0] }
)
1 change: 1 addition & 0 deletions lib/tork/config/test/master.rb
@@ -1,4 +1,5 @@
$LOAD_PATH.unshift 'test' unless $LOAD_PATH.include? 'test'
$LOAD_PATH.unshift 'lib' unless $LOAD_PATH.include? 'lib'
require 'test_helper' if File.exist? 'test/test_helper.rb'
require './test_helper' if File.exist? 'test_helper.rb'
require 'minitest/autorun' if defined? MiniTest
2 changes: 1 addition & 1 deletion lib/tork/config/test/worker.rb
@@ -1,4 +1,4 @@
if $tork_test_file.start_with? 'test/' and $tork_line_numbers.any?
if $tork_line_numbers.any? and $tork_test_file =~ $tork_config_test_grep
test_file_lines = File.readlines($tork_test_file)
test_names = $tork_line_numbers.map do |line|
catch :found do
Expand Down

0 comments on commit 0a03b80

Please sign in to comment.