Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created March 10, 2015 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/4695587283008c0b8716 to your computer and use it in GitHub Desktop.
Save tenderlove/4695587283008c0b8716 to your computer and use it in GitHub Desktop.
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index 739823b..45000bc 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -75,6 +75,27 @@ module ActiveSupport
alias :assert_not_respond_to :refute_respond_to
alias :assert_not_same :refute_same
+ class FileAndLineFilter < Struct.new(:klass, :file, :line)
+ def === method
+ return false unless klass.method_defined? method
+ test_file, test_line = klass.instance_method(method).source_location
+ test_file == file && test_line == line
+ end
+ end
+
+ def self.run reporter, options = {}
+ if file_and_line? options[:filter]
+ options = options.dup
+ options[:filter] =~ /^(.*):(\d+)/
+ options[:filter] = FileAndLineFilter.new(self, $1, $2.to_i)
+ end
+ super(reporter, options)
+ end
+
+ def self.file_and_line? option
+ option && option =~ /:\d+/
+ end
+
# Fails if the block raises an exception.
#
# assert_nothing_raised do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment