Permalink
Browse files

refactor `Runner#run` so `#initialize` doesn't exec anything

  • Loading branch information...
1 parent ba3f149 commit 94d958d780b6b6423652d2be609931b8d8db90b2 @qrush committed Jan 12, 2012
Showing with 21 additions and 8 deletions.
  1. +2 −0 lib/m.rb
  2. +19 −8 lib/m/runner.rb
View
@@ -84,6 +84,8 @@
require "ostruct"
#### External requires
+# Instead of using rake/rake_test_loader and reduplicating logic there, just use `TestTask`.
+require "rake/testtask"
# After trying several source parsing libraries, this is the only one that seems to work consistently.
require "method_source"
View
@@ -3,28 +3,41 @@ module M
# Instead of slamming all of this junk in an `M` class, it's here instead.
class Runner
def initialize(argv)
+ @argv = argv
+ end
+
+ def run
+ parse
+ execute
+ end
+
+ private
+
+ def parse
# With no arguments,
- if argv.empty?
+ if @argv.empty?
# Just shell out to `rake test`.
exec "rake test"
else
# Parse out ARGV, it should be coming in in a format like `test/test_file.rb:9`
- @file, line = argv.first.split(':')
+ @file, line = @argv.first.split(':')
@line = line.to_i
+ # If this file is a directory, not a file, run the tests inside of this directory
if Dir.exist?(@file)
- require 'rake/testtask'
- Rake::TestTask.new(:custom) do |t|
+ # Make a new rake task with a hopefully unique name, and run every test looking file in it
+ Rake::TestTask.new(:m_custom) do |t|
t.libs << 'test'
t.pattern = "#{@file}/*test*.rb"
end
- Rake::Task['custom'].invoke
+ # Invoke the rake task and exit, hopefully it'll work!
+ Rake::Task['m_custom'].invoke
exit
end
end
end
- def run
+ def execute
# Locate tests to run that may be inside of this line. There could be more than one!
tests_to_run = tests.within(@line)
@@ -50,8 +63,6 @@ def run
end
end
- private
-
# Finds all test suites in this test file, with test methods included.
def suites
# Since we're not using `ruby -Itest` to run the tests, we need to add this directory to the `LOAD_PATH`

0 comments on commit 94d958d

Please sign in to comment.