Revert "Replace `method_source` gem with stdlib equivalent"

This commit is contained in:
Rafael Mendonça França 2022-09-08 16:58:52 -04:00 committed by GitHub
parent bee6167977
commit ff9739217d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 54 deletions

View File

@ -94,6 +94,7 @@ PATH
railties (7.1.0.alpha)
actionpack (= 7.1.0.alpha)
activesupport (= 7.1.0.alpha)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.6)
@ -314,6 +315,7 @@ GEM
marcel (1.0.2)
matrix (0.4.2)
memoist (0.16.2)
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)

View File

@ -1,10 +1,10 @@
# frozen_string_literal: true
require "shellwords"
require "method_source"
require "rake/file_list"
require "active_support"
require "active_support/core_ext/module/attribute_accessors"
require "ripper"
module Rails
module TestUnit
@ -169,33 +169,10 @@ module Rails
private
def definition_for(method)
file, start_line = method.source_location
end_line = MethodEndFinder.call(source: File.read(file), target: method.name)
end_line = method.source.count("\n") + start_line - 1
return file, start_line..end_line
end
# Finds the line number where the definition of method named +target+ ends.
module MethodEndFinder # :nodoc:
def self.call(source:, target:)
catch(:line_number_is) do
DefParser.new(source: source, target: target).parse
return nil
end
end
class DefParser < Ripper # :nodoc:
def initialize(source:, target:)
@target = String(target)
super(source)
end
def on_def(method_name, *)
if method_name == @target
throw(:line_number_is, lineno)
end
end
end
end
end
end
end

View File

@ -42,6 +42,7 @@ Gem::Specification.new do |s|
s.add_dependency "rake", ">= 12.2"
s.add_dependency "thor", "~> 1.0"
s.add_dependency "method_source"
s.add_dependency "zeitwerk", "~> 2.6"
s.add_development_dependency "actionview", version

View File

@ -376,7 +376,7 @@ module ApplicationTests
end
end
def test_more_than_one_line_filter_macro_syntax
def test_more_than_one_line_filter
app_file "test/models/post_test.rb", <<-RUBY
require "test_helper"
@ -404,34 +404,6 @@ module ApplicationTests
end
end
def test_more_than_one_line_filter_test_method_syntax
app_file "test/models/post_test.rb", <<-RUBY
require "test_helper"
class PostTest < ActiveSupport::TestCase
def test_first_filter
puts 'PostTest:FirstFilter'
assert true
end
def test_second_filter
puts 'PostTest:SecondFilter'
assert true
end
def test_line_filter_does_not_run_this
assert true
end
end
RUBY
run_test_command("test/models/post_test.rb:4:9").tap do |output|
assert_match "PostTest:FirstFilter", output
assert_match "PostTest:SecondFilter", output
assert_match "2 runs, 2 assertions", output
end
end
def test_more_than_one_line_filter_with_multiple_files
app_file "test/models/account_test.rb", <<-RUBY
require "test_helper"