Class: RSpecParser

Inherits:
Object
  • Object
show all
Defined in:
lib/files/RSpecParser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ RSpecParser

Returns a new instance of RSpecParser.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/files/RSpecParser.rb', line 20

def initialize(file_name)
  file = file_name
  @top_node = Parser::CurrentRuby.parse_file(file)
  @ids = []
  @metadata = {}
  @skips = []
  test_cases = []
  @skips_in_before = []
  @condition_set = false
  @indent_amount = "     "
  @in_testrail_id = false
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



18
19
20
# File 'lib/files/RSpecParser.rb', line 18

def file
  @file
end

#test_casesObject (readonly)

Returns the value of attribute test_cases.



18
19
20
# File 'lib/files/RSpecParser.rb', line 18

def test_cases
  @test_cases
end

#verboseObject

Returns the value of attribute verbose.



19
20
21
# File 'lib/files/RSpecParser.rb', line 19

def verbose
  @verbose
end

Instance Method Details

#dump_astObject

Prints to standard out the full, unvarnished abstract syntax tree in all it’s ugliness.



53
54
55
56
# File 'lib/files/RSpecParser.rb', line 53

def dump_ast
  print_ast(@top_node, "")
  puts ""
end

#inspectObject

Prints to standard out the test cases that were generated by parsing the file



46
47
48
49
50
# File 'lib/files/RSpecParser.rb', line 46

def inspect
  test_cases.each do |tc|
    puts tc.print
  end
end

#parse(verbosity: false) ⇒ Object

Performs the parsing of the rspec file and generates an array of TestCase instances



34
35
36
37
38
39
40
41
42
43
# File 'lib/files/RSpecParser.rb', line 34

def parse(verbosity:false)
  verbose = verbosity
  traverse(@top_node, "")
  # get the last one added to the array
  test_cases << @current_test_case.clone
  test_cases.each do |tc|
    tc.skip += @skips_in_before
  end
  puts "" if verbose
end