Class: Rails::TestUnit::TestParser
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Ripper
|
|
Instance Chain:
self,
Ripper
|
|
Inherits: |
Ripper
|
Defined in: | railties/lib/rails/test_unit/test_parser.rb |
Overview
Parse a test file to extract the line ranges of all tests in both method-style (def test_foo) and declarative-style (test “foo” do)
Class Method Summary
-
.definition_for(method_obj)
Helper to translate a method object into the path and line range where the method was defined.
- .new ⇒ TestParser constructor
Instance Method Summary
- #first_arg(arg) (also: #on_method_add_arg, #on_command, #on_stmts_add, #on_arg_paren, #on_bodystmt)
- #just_lineno (also: #on_ident, #on_do_block, #on_stmts_new, #on_brace_block)
-
#on_arg_paren(arg)
Alias for #first_arg.
- #on_args_add(parts, part)
- #on_args_add_block(args, *rest)
- #on_args_new
-
#on_bodystmt(arg)
Alias for #first_arg.
-
#on_brace_block
Alias for #just_lineno.
-
#on_command(arg)
Alias for #first_arg.
- #on_command_call(begin_lineno, _args)
-
#on_def(begin_line)
method test e.g.
-
#on_do_block
Alias for #just_lineno.
-
#on_ident
Alias for #just_lineno.
-
#on_method_add_arg(arg)
Alias for #first_arg.
-
#on_method_add_block(begin_line, end_line)
Everything past this point is to support declarative tests, which require more work to get right because of the many different ways methods can be invoked in ruby, all of which are parsed differently.
-
#on_stmts_add(arg)
Alias for #first_arg.
-
#on_stmts_new
Alias for #just_lineno.
- #parse
Constructor Details
.new ⇒ TestParser
# File 'railties/lib/rails/test_unit/test_parser.rb', line 19
def initialize(*) # A hash mapping the 1-indexed line numbers that tests start on to where they end. @begins_to_ends = {} super end
Class Method Details
.definition_for(method_obj)
Helper to translate a method object into the path and line range where the method was defined.
Instance Method Details
#first_arg(arg) Also known as: #on_method_add_arg, #on_command, #on_stmts_add, #on_arg_paren, #on_bodystmt
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 56
def first_arg(arg, *) arg end
#just_lineno Also known as: #on_ident, #on_do_block, #on_stmts_new, #on_brace_block
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 60
def just_lineno(*) lineno end
#on_arg_paren(arg)
Alias for #first_arg.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 67
alias on_arg_paren first_arg
#on_args_add(parts, part)
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 79
def on_args_add(parts, part) parts << part end
#on_args_add_block(args, *rest)
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 83
def on_args_add_block(args, *rest) args.first end
#on_args_new
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 75
def on_args_new [] end
#on_bodystmt(arg)
Alias for #first_arg.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 68
alias on_bodystmt first_arg
#on_brace_block
Alias for #just_lineno.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 73
alias on_brace_block just_lineno
#on_command(arg)
Alias for #first_arg.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 65
alias on_command first_arg
#on_command_call(begin_lineno, _args)
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 52
def on_command_call(*, begin_lineno, _args) begin_lineno end
#on_def(begin_line)
method test e.g. def test_some_description
This event’s first argument gets the ident
node containing the method name, which we have overridden to return the line number of the ident instead.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 34
def on_def(begin_line, *) @begins_to_ends[begin_line] = lineno end
#on_do_block
Alias for #just_lineno.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 71
alias on_do_block just_lineno
#on_ident
Alias for #just_lineno.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 70
alias on_ident just_lineno
#on_method_add_arg(arg)
Alias for #first_arg.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 64
alias on_method_add_arg first_arg
#on_method_add_block(begin_line, end_line)
Everything past this point is to support declarative tests, which require more work to get right because of the many different ways methods can be invoked in ruby, all of which are parsed differently.
The approach is just to store the current line number when the “test” method is called and pass it up the tree so it’s available at the point when we also know the line where the associated block ends.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 46
def on_method_add_block(begin_line, end_line) if begin_line && end_line @begins_to_ends[begin_line] = end_line end end
#on_stmts_add(arg)
Alias for #first_arg.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 66
alias on_stmts_add first_arg
#on_stmts_new
Alias for #just_lineno.
# File 'railties/lib/rails/test_unit/test_parser.rb', line 72
alias on_stmts_new just_lineno
#parse
[ GitHub ]# File 'railties/lib/rails/test_unit/test_parser.rb', line 25
def parse super @begins_to_ends end