Permalink
Browse files

Run `rake test` if `m` is run with no arguments. Closes #5

  • Loading branch information...
1 parent 2fbc184 commit 1b1ef2d3f9709633abe07e2731029a24ad3cff83 @qrush committed Jan 12, 2012
Showing with 46 additions and 27 deletions.
  1. +1 −1 Rakefile
  2. +9 −3 lib/m/runner.rb
  3. +6 −0 test/Rakefile
  4. +11 −11 test/active_support_test.rb
  5. +3 −3 test/multiple_test.rb
  6. +3 −1 test/test_helper.rb
  7. +13 −8 test/test_unit_test.rb
View
@@ -3,7 +3,7 @@ require "bundler/gem_tasks"
require 'rake/clean'
require "rake/testtask"
-task :default => [:docs, :test]
+task :default => [:test]
Rake::TestTask.new do |t|
t.libs << 'test'
View
@@ -3,9 +3,15 @@ module M
# Instead of slamming all of this junk in an `M` class, it's here instead.
class Runner
def initialize(argv)
- # Parse out ARGV, it should be coming in in a format like `test/test_file.rb:9`
- @file, line = argv.first.split(':')
- @line = line.to_i
+ # With no arguments,
+ 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(':')
+ @line = line.to_i
+ end
end
def run
View
@@ -0,0 +1,6 @@
+require "rake/testtask"
+
+Rake::TestTask.new do |t|
+ t.libs << '.'
+ t.pattern = 'examples/*_test.rb'
+end
@@ -2,47 +2,47 @@
class ActiveSupportTest < MTest
def test_run_simple_test_by_line_number
- output = m('test/examples/active_support_example_test.rb:11')
+ output = m('examples/active_support_example_test.rb:11')
assert_output /1 tests, 1 assertions/, output
end
def test_runs_entire_test_without_line_number
- output = m('test/examples/active_support_example_test.rb')
+ output = m('examples/active_support_example_test.rb')
assert_output /4 tests/, output
end
def test_run_inside_of_test
- output = m('test/examples/active_support_example_test.rb:12')
+ output = m('examples/active_support_example_test.rb:12')
assert_output /1 tests, 1 assertions/, output
end
def test_run_on_end_of_test
- output = m('test/examples/active_support_example_test.rb:13')
+ output = m('examples/active_support_example_test.rb:13')
assert_output /1 tests, 1 assertions/, output
end
def test_run_inside_big_test
- output = m('test/examples/active_support_example_test.rb:17')
+ output = m('examples/active_support_example_test.rb:17')
assert_output /1 tests, 3 assertions/, output
end
def test_run_on_blank_line_orders_tests_by_line_number
- output = m('test/examples/active_support_example_test.rb:2')
+ output = m('examples/active_support_example_test.rb:2')
assert !$?.success?
expected = <<-EOF
No tests found on line 2. Valid tests to run:
- test_normal: m test/examples/active_support_example_test.rb:7
- test_carrot: m test/examples/active_support_example_test.rb:11
- test_daikon: m test/examples/active_support_example_test.rb:15
-test_eggplant_fig: m test/examples/active_support_example_test.rb:21
+ test_normal: m examples/active_support_example_test.rb:7
+ test_carrot: m examples/active_support_example_test.rb:11
+ test_daikon: m examples/active_support_example_test.rb:15
+test_eggplant_fig: m examples/active_support_example_test.rb:21
EOF
assert_equal expected.strip, output
end
def test_run_on_test_with_spaces
- output = m('test/examples/active_support_example_test.rb:21')
+ output = m('examples/active_support_example_test.rb:21')
assert_output /1 tests, 1 assertions/, output
end
end
@@ -2,17 +2,17 @@
class MultipleTest < MTest
def test_run_simple_test_by_line_number
- output = m('test/examples/multiple_example_test.rb:11')
+ output = m('examples/multiple_example_test.rb:11')
assert_output /1 tests, 1 assertions/, output
end
def test_runs_entire_test_without_line_number
- output = m('test/examples/multiple_example_test.rb')
+ output = m('examples/multiple_example_test.rb')
assert_output /4 tests/, output
end
def test_runs_all_tests_on_given_line_number
- output = m('test/examples/multiple_example_test.rb:6')
+ output = m('examples/multiple_example_test.rb:6')
assert_output /3 tests/, output
end
end
View
@@ -4,7 +4,9 @@
class MTest < Test::Unit::TestCase
def m(arguments)
- `ruby -Ilib ./bin/m #{arguments} 2>&1`.strip
+ Dir.chdir("test") do
+ `ruby -I../lib -I. ../bin/m #{arguments} 2>&1`.strip
+ end
end
def assert_output(regexp, output)
@@ -2,36 +2,41 @@
class TestUnitTest < MTest
def test_run_simple_test_by_line_number
- output = m('test/examples/test_unit_example_test.rb:7')
+ output = m('examples/test_unit_example_test.rb:7')
assert_output /1 tests, 1 assertions/, output
end
def test_runs_entire_test_without_line_number
- output = m('test/examples/test_unit_example_test.rb')
+ output = m('examples/test_unit_example_test.rb')
assert_output /2 tests/, output
end
+ def test_runs_entire_test_suite_with_no_arguments
+ output = m('')
+ assert_output /10 tests/, output
+ end
+
def test_run_inside_of_test
- output = m('test/examples/test_unit_example_test.rb:8')
+ output = m('examples/test_unit_example_test.rb:8')
assert_output /1 tests, 1 assertions/, output
end
def test_run_on_end_of_test
- output = m('test/examples/test_unit_example_test.rb:9')
+ output = m('examples/test_unit_example_test.rb:9')
assert_output /1 tests, 1 assertions/, output
end
def test_run_inside_big_test
- output = m('test/examples/test_unit_example_test.rb:14')
+ output = m('examples/test_unit_example_test.rb:14')
assert_output /1 tests, 3 assertions/, output
end
def test_run_on_blank_line
- output = m('test/examples/test_unit_example_test.rb:2')
+ output = m('examples/test_unit_example_test.rb:2')
assert !$?.success?
assert_match /No tests found on line 2. Valid tests to run:/, output
- assert_match %r{ test_apple: m test/examples/test_unit_example_test\.rb:7}, output
- assert_match %r{test_banana: m test/examples/test_unit_example_test\.rb:11}, output
+ assert_match %r{ test_apple: m examples/test_unit_example_test\.rb:7}, output
+ assert_match %r{test_banana: m examples/test_unit_example_test\.rb:11}, output
end
end

0 comments on commit 1b1ef2d

Please sign in to comment.