Permalink
Browse files

+ Allow filtering tests by suite name as well as test name. (lazyatom)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8161]
  • Loading branch information...
zenspider committed Jan 30, 2013
1 parent ef04d90 commit 3dd26d4c190129c59f48e191f94ec309c338a9df
Showing with 38 additions and 1 deletion.
  1. +6 −0 lib/minitest/parallel_each.rb
  2. +6 −1 lib/minitest/unit.rb
  3. +26 −0 test/minitest/test_minitest_unit.rb
@@ -27,6 +27,12 @@ def grep pattern # :nodoc:
self.class.new super
end
+ def select(&block) # :nodoc:
+ self.class.new super
+ end
+
+ alias find_all select # :nodoc:
+
##
# Starts N threads that yield each element to your block. Joins the
# threads at the end.
View
@@ -908,7 +908,12 @@ def _run_suite suite, type
filter = options[:filter] || '/./'
filter = Regexp.new $1 if filter =~ /\/(.*)\//
- assertions = suite.send("#{type}_methods").grep(filter).map { |method|
+ all_test_methods = suite.send "#{type}_methods"
+ filtered_test_methods = all_test_methods.find_all { |m|
+ "#{suite}##{m}" =~ filter

This comment has been minimized.

Show comment Hide comment
@lazyatom

lazyatom Jan 30, 2013

I think you might need to use something like match here, because IIRC if the filter option isn't a Regexp (i.e. -n "test_something" then the =~ operation will fail with a type mismatch.

@lazyatom

lazyatom Jan 30, 2013

I think you might need to use something like match here, because IIRC if the filter option isn't a Regexp (i.e. -n "test_something" then the =~ operation will fail with a type mismatch.

This comment has been minimized.

Show comment Hide comment
@zenspider

zenspider Jan 30, 2013

Member
@zenspider

zenspider via email Jan 30, 2013

Member

This comment has been minimized.

Show comment Hide comment
@zenspider

zenspider Jan 30, 2013

Member
@zenspider

zenspider via email Jan 30, 2013

Member

This comment has been minimized.

Show comment Hide comment
@lazyatom

lazyatom Jan 30, 2013

No problem, glad to help.

@lazyatom

lazyatom Jan 30, 2013

No problem, glad to help.

+ }
+
+ assertions = filtered_test_methods.map { |method|
inst = suite.new method
inst._assertions = 0
@@ -389,6 +389,32 @@ def test_failure
assert_report expected, %w[--name /some|thing/ --seed 42]
end
+ def test_run_filtered_including_suite_name
+ alpha = Class.new MiniTest::Unit::TestCase do
+ def test_something
+ assert false
+ end
+ end
+ self.class.const_set(:Alpha, alpha)
+
+ beta = Class.new MiniTest::Unit::TestCase do
+ def test_something
+ assert true
+ end
+ end
+ self.class.const_set(:Beta, beta)
+
+ expected = clean <<-EOM
+ .
+
+ Finished tests in 0.00
+
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+ EOM
+
+ assert_report expected, %w[--name /Beta#test_something/ --seed 42]
+ end
+
def test_run_passing
Class.new MiniTest::Unit::TestCase do
def test_something

0 comments on commit 3dd26d4

Please sign in to comment.