onlyoffice_rspec_parser 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 51d18f456879010c62bd1ae7cde93a75794edd15f0ceec7f13b868567f868d98
4
+ data.tar.gz: 6b0bbe309f1a946074ab61a7a82d532b3749ee34c52bef94f5a18ed4a487c3e4
5
+ SHA512:
6
+ metadata.gz: a34f284d9930e0c6c0510fd1c0ac2f26247b3b46eaa8f0b0f93a6ff9d82fb332c6c013410479d11e9891cb4db7a03180b2a8790bb15c2dc04d534e50ea881aa5
7
+ data.tar.gz: eaf8ebdf88a032da128c3d94aeb249172b6429007aff24cf63d09ff9e146094da98ed92109d6991c080fdb7f850afb41f85c2706b3db60795e08ff1ccf38bc30
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onlyoffice_rspec_parser/rspec_parser'
4
+ require 'onlyoffice_rspec_parser/spec_parsed'
5
+ require 'onlyoffice_rspec_parser/version'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeRspecParser
4
+ NAME = 'onlyoffice_rspec_parser'
5
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onlyoffice_logger_helper'
4
+ module OnlyofficeRspecParser
5
+ # Static parsing of _rspec.rb files
6
+ class SpecParser
7
+ def self.get_it_mass_by_path(path_to_spec)
8
+ raise "File not exists: #{path_to_spec}!" unless File.exist?(path_to_spec)
9
+
10
+ test_file = File.new(path_to_spec)
11
+ file_tests = []
12
+ test_file.each do |line|
13
+ next unless /it [\'\"](.*)?[\'\"] do/.match?(line)
14
+
15
+ test_name = line.scan(/it [\'\"](.*?)[\'\"] do/)
16
+ file_tests << test_name.first.first
17
+ end
18
+ test_file.close
19
+ file_tests
20
+ end
21
+
22
+ def self.uniq_duplicates(path_to_spec)
23
+ case_names = get_it_mass_by_path(path_to_spec)
24
+ duplicates = case_names.find_all { |e| case_names.count(e) > 1 }
25
+ duplicates.uniq
26
+ end
27
+
28
+ def self.check_for_doubles(path_to_spec)
29
+ duplicates = uniq_duplicates(path_to_spec)
30
+ if duplicates.empty?
31
+ OnlyofficeLoggerHelper.log("No duplicates in file #{path_to_spec}")
32
+ else
33
+ OnlyofficeLoggerHelper.log("Duplicate names in file #{path_to_spec}:")
34
+ duplicates.each do |cur_dup|
35
+ OnlyofficeLoggerHelper.log("\t#{cur_dup}")
36
+ end
37
+ end
38
+ duplicates
39
+ end
40
+
41
+ def self.check_folder_for_spec_doubles(folder)
42
+ files = Dir.glob("#{folder}/**/*_spec.*")
43
+ files.each do |cur_file|
44
+ check_for_doubles(cur_file)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parser/current'
4
+ require 'onlyoffice_file_helper'
5
+ require_relative 'spec_parsed/it_parsed'
6
+ module OnlyofficeRspecParser
7
+ # Class for storing data of parsed spec
8
+ class SpecParsed
9
+ attr_reader :file
10
+
11
+ def initialize(path)
12
+ @file = path
13
+ @parsed_data = Parser::CurrentRuby.parse(File.read(file))
14
+ end
15
+
16
+ # @return [Array<ItParsed>] list of it nodes in spec
17
+ def it_nodes
18
+ @it_nodes ||= search_node_for_it(@parsed_data)
19
+ end
20
+
21
+ def search_node_for_it(node)
22
+ nodes = []
23
+ node.children.each do |child|
24
+ next unless child.is_a?(Parser::AST::Node)
25
+
26
+ if child.to_s.start_with?("(send nil :it\n")
27
+ nodes << ItParsed.new(node, file)
28
+ else
29
+ nodes += search_node_for_it(child)
30
+ end
31
+ end
32
+ nodes
33
+ end
34
+
35
+ # @return [Nothing] find specs without expect
36
+ def self.find_spec_without_expect(folder)
37
+ files = OnlyofficeFileHelper::FileHelper.list_file_in_directory(folder)
38
+ files.each do |file|
39
+ next unless file.end_with?('_spec.rb')
40
+
41
+ parsed_spec = SpecParsed.new(file)
42
+ parsed_spec.it_nodes.each do |current_it|
43
+ next if current_it.include_expect?
44
+
45
+ OnlyofficeLoggerHelper.log("There is no expect in #{current_it}")
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeRspecParser
4
+ # Class for storing data of `it`
5
+ class ItParsed
6
+ def initialize(node, file)
7
+ @node = node
8
+ @file = file
9
+ end
10
+
11
+ def to_s
12
+ "#{@file}:#{@node.loc.expression.to_s.split(':')[1]}"
13
+ end
14
+
15
+ # @return [True, False] check if node include `expect`
16
+ def include_expect?
17
+ @node.children.last.to_s.match?(/\:expect\)?\n/)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeRspecParser
4
+ VERSION = '0.2.0'
5
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlyoffice_rspec_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - ONLYOFFICE
8
+ - Pavel Lobashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: onlyoffice_file_helper
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: onlyoffice_logger_helper
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: parser
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '13.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '13.0'
70
+ description: Gem for static parsing of _rspec.rb files
71
+ email:
72
+ - shockwavenn@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - lib/onlyoffice_rspec_parser.rb
78
+ - lib/onlyoffice_rspec_parser/name.rb
79
+ - lib/onlyoffice_rspec_parser/rspec_parser.rb
80
+ - lib/onlyoffice_rspec_parser/spec_parsed.rb
81
+ - lib/onlyoffice_rspec_parser/spec_parsed/it_parsed.rb
82
+ - lib/onlyoffice_rspec_parser/version.rb
83
+ homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_parser
84
+ licenses:
85
+ - AGPL-3.0
86
+ metadata:
87
+ bug_tracker_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_parser/issues
88
+ changelog_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_parser/blob/master/CHANGELOG.md
89
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_rspec_parser
90
+ homepage_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_parser
91
+ source_code_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_parser
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '2.4'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Parse rspec
111
+ test_files: []