diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-06-08 12:05:12 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-06-08 12:05:12 +0200 |
commit | e8d02ccf8c485cd2e5f6e32713bd8fc23b7b5560 (patch) | |
tree | d6b8e1a26a3e69e38f14c2e61f698ab8e0fe5042 /activesupport | |
parent | 8e7f8ef5d6209367734530b258f5fbeb0fc24c28 (diff) | |
parent | b6fc8e25a10cc4abdd03018798b180270d6c5d7f (diff) | |
download | rails-e8d02ccf8c485cd2e5f6e32713bd8fc23b7b5560.tar.gz rails-e8d02ccf8c485cd2e5f6e32713bd8fc23b7b5560.tar.bz2 rails-e8d02ccf8c485cd2e5f6e32713bd8fc23b7b5560.zip |
Merge pull request #19571 from kaspth/improve-runner-integration
Improve Test Runner's Minitest integration.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/test_case.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/composite_filter.rb | 54 |
2 files changed, 64 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index d9a668c0ea..ae6f00b861 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -9,6 +9,7 @@ require 'active_support/testing/isolation' require 'active_support/testing/constant_lookup' require 'active_support/testing/time_helpers' require 'active_support/testing/file_fixtures' +require 'active_support/testing/composite_filter' require 'active_support/core_ext/kernel/reporting' module ActiveSupport @@ -38,6 +39,15 @@ module ActiveSupport def test_order ActiveSupport.test_order ||= :random end + + def run(reporter, options = {}) + if options[:patterns] && options[:patterns].any? { |p| p =~ /:\d+/ } + options[:filter] = \ + Testing::CompositeFilter.new(self, options[:filter], options[:patterns]) + end + + super + end end alias_method :method_name, :name diff --git a/activesupport/lib/active_support/testing/composite_filter.rb b/activesupport/lib/active_support/testing/composite_filter.rb new file mode 100644 index 0000000000..bde723e30b --- /dev/null +++ b/activesupport/lib/active_support/testing/composite_filter.rb @@ -0,0 +1,54 @@ +require 'method_source' + +module ActiveSupport + module Testing + class CompositeFilter # :nodoc: + def initialize(runnable, filter, patterns) + @runnable = runnable + @filters = [ derive_regexp(filter), *derive_line_filters(patterns) ].compact + end + + def ===(method) + @filters.any? { |filter| filter === method } + end + + private + def derive_regexp(filter) + filter =~ %r%/(.*)/% ? Regexp.new($1) : filter + end + + def derive_line_filters(patterns) + patterns.map do |file_and_line| + file, line = file_and_line.split(':') + Filter.new(@runnable, file, line) if file + end + end + + class Filter # :nodoc: + def initialize(runnable, file, line) + @runnable, @file = runnable, File.expand_path(file) + @line = line.to_i if line + end + + def ===(method) + return unless @runnable.method_defined?(method) + + if @line + test_file, test_range = definition_for(@runnable.instance_method(method)) + test_file == @file && test_range.include?(@line) + else + @runnable.instance_method(method).source_location.first == @file + end + end + + private + def definition_for(method) + file, start_line = method.source_location + end_line = method.source.count("\n") + start_line - 1 + + return file, start_line..end_line + end + end + end + end +end |