Module: TestProf::RSpecStamp::Parser
- Defined in:
- lib/test_prof/rspec_stamp/parser.rb
Overview
Parse examples headers
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Class Method Details
.parse(code) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/test_prof/rspec_stamp/parser.rb', line 28 def parse(code) sexp = Ripper.sexp(code) return unless sexp # sexp has the following format: # [:program, # [ # [ # :command, # [:@ident, "it", [1, 0]], # [:args_add_block, [ ... ]] # ] # ] # ] # # or # # [:program, # [ # [ # :vcall, # [:@ident, "it", [1, 0]] # ] # ] # ] res = Result.new fcall = sexp[1][0][1] fcall = fcall[1] if fcall.first == :fcall res.fname = fcall[1] args_block = sexp[1][0][2] return res if args_block.nil? args_block = args_block[1] if args_block.first == :arg_paren args = args_block[1] if args.first.first == :string_literal res.desc = parse_literal(args.shift) end parse_arg(res, args.shift) until args.empty? res end |