robotag 1.0.0 → 2.0.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.
- checksums.yaml +4 -4
- data/lib/robotag.rb +71 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec985055f4c9d4c0433884d83032aa9da032146a59a834775e48a9887d10784
|
4
|
+
data.tar.gz: 3f24cd962472659a3cbc99a6b4780e3df748eac943055cbd8b66288387cd65b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f47d741e49ff2be4722de01b33eb5b410e459a5766ed4c543c25e828a1903447bcc438c4d087ab5f39a00841608ee85315cc7950cee75a829944524e418d4d6
|
7
|
+
data.tar.gz: 1a72c50d795145710e075bde7e5e08c215ddcf148c3f3ea6de5a38ef993a1b3bc6414e8d686d691adb0ffc30c74ed5121b54214e07e9f768981f8dfe109fef10
|
data/lib/robotag.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'cql'
|
2
2
|
|
3
3
|
class Robotag
|
4
|
-
attr_accessor :repo, :chain_state
|
4
|
+
attr_accessor :repo, :chain_state, :write_directives
|
5
5
|
|
6
6
|
def initialize(opts)
|
7
7
|
self.repo = CQL::Repository.new(opts[:repo])
|
8
|
+
self.write_directives = {}
|
8
9
|
self
|
9
10
|
end
|
10
11
|
|
11
12
|
def tests_with_steps_that_match(my_regex)
|
12
13
|
self.chain_state = self.repo.query do
|
13
|
-
select
|
14
|
+
select
|
14
15
|
from scenarios, outlines
|
15
16
|
with { |scenario| scenario.steps.map(&:text).any? { |step| step =~ my_regex } }
|
16
17
|
end
|
@@ -19,7 +20,7 @@ class Robotag
|
|
19
20
|
|
20
21
|
def all_have_tag?(tag)
|
21
22
|
self.chain_state = self.chain_state.map do |query_result|
|
22
|
-
query_result[
|
23
|
+
query_result[:self].tags.map do |cm_tag|
|
23
24
|
cm_tag.map(&:name)
|
24
25
|
end
|
25
26
|
end.all? do |mapped_qr|
|
@@ -30,7 +31,73 @@ class Robotag
|
|
30
31
|
self
|
31
32
|
end
|
32
33
|
|
34
|
+
# This is heavily borrowed from https://raw.githubusercontent.com/enkessler/cuke_cataloger/master/lib/cuke_cataloger/unique_test_case_tagger.rb
|
35
|
+
# Specifically it is an adapted version of #tag_tests
|
36
|
+
def tag_all_with(tag)
|
37
|
+
warn('This script will potentially rewrite all of your feature files. Please be patient and remember to tip your source control system.') # rubocop:disable Metrics/LineLength
|
38
|
+
|
39
|
+
# Analysis and output
|
40
|
+
self.chain_state.map { |query_result| query_result[:self] }.each do |test|
|
41
|
+
if (test.is_a?(CukeModeler::Scenario) || test.is_a?(CukeModeler::Outline))
|
42
|
+
add_tag(test, tag)
|
43
|
+
else
|
44
|
+
raise("Unknown test type: #{test.class}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_tag(test, tag)
|
51
|
+
return if has_tag?(test, tag)
|
52
|
+
|
53
|
+
tag_test(test, tag)
|
54
|
+
end
|
55
|
+
|
56
|
+
def tag_test(test, tag)
|
57
|
+
feature_file = test.get_ancestor(:feature_file)
|
58
|
+
file_path = feature_file.path
|
59
|
+
|
60
|
+
tag_index = (test.source_line - 2)
|
61
|
+
|
62
|
+
file_lines = if self.write_directives[file_path].nil?
|
63
|
+
File.readlines(file_path)
|
64
|
+
else
|
65
|
+
self.write_directives[file_path].split("\n").map {|line| line + "\n"}
|
66
|
+
end
|
67
|
+
file_lines[tag_index] = "#{file_lines[tag_index].chomp} #{tag}\n"
|
68
|
+
|
69
|
+
self.write_directives[file_path] = file_lines.join
|
70
|
+
|
71
|
+
new_tag = CukeModeler::Tag.new
|
72
|
+
new_tag.name = tag
|
73
|
+
test.tags << new_tag
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
def has_tag?(test, tag)
|
78
|
+
test.tags.map(&:name).include?(tag)
|
79
|
+
end
|
80
|
+
|
81
|
+
def preview
|
82
|
+
unless self.write_directives.empty?
|
83
|
+
dirname = "robotag_preview"
|
84
|
+
FileUtils.rm_rf(dirname)
|
85
|
+
self.write_directives.each do |filepath, file_contents|
|
86
|
+
FileUtils.mkdir_p(File.dirname("#{dirname}/#{filepath}"))
|
87
|
+
File.open("#{dirname}/#{filepath}", 'w+') do |tmp_file|
|
88
|
+
tmp_file.print file_contents
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
33
94
|
def go!
|
34
|
-
self.
|
95
|
+
if !self.write_directives.empty?
|
96
|
+
self.write_directives.each do |file_path, joined_file_lines|
|
97
|
+
File.open(file_path, 'w+') { |file| file.print joined_file_lines }
|
98
|
+
end
|
99
|
+
else
|
100
|
+
self.chain_state
|
101
|
+
end
|
35
102
|
end
|
36
103
|
end
|