robotag 1.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/robotag.rb +92 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab44b297b1fd2c5f003e7825deb734e12d46dc62470b02abd3da9feed0b9bdbc
|
4
|
+
data.tar.gz: ab1d7b1ddae29e276e481a7c72d957c1526c5cac46414ba604e30132a5983d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ea9fed578bce9a570ce0a526d0e5ec2c83d466a50eac068b5d95cdda7cdfb5cf3e741efe7ac011b6c9fc89b25c20496fd462fd02a2d431ac047ac69659d4919
|
7
|
+
data.tar.gz: f22e93f4f1dfc97ee5851795214a3f909cf285466f306cd32bd0fc59f05bf192c71ebe17b81df86fbdcfc4ca14e8fe6a85d8038df6a382784b186c369e042cfc
|
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,94 @@ 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(tag, :add)
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_all(tag)
|
44
|
+
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
|
45
|
+
|
46
|
+
analysis_and_output(tag, :remove)
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_tag(test, tag, action)
|
51
|
+
if action == :add
|
52
|
+
return if has_tag?(test, tag)
|
53
|
+
elsif action == :remove
|
54
|
+
return unless has_tag?(test, tag)
|
55
|
+
end
|
56
|
+
|
57
|
+
modify_test_tag(test, tag, action)
|
58
|
+
end
|
59
|
+
|
60
|
+
def modify_test_tag(test, tag, action)
|
61
|
+
feature_file = test.get_ancestor(:feature_file)
|
62
|
+
file_path = feature_file.path
|
63
|
+
|
64
|
+
tag_index = (test.source_line - 2)
|
65
|
+
|
66
|
+
file_lines = if self.write_directives[file_path].nil?
|
67
|
+
File.readlines(file_path)
|
68
|
+
else
|
69
|
+
self.write_directives[file_path].split("\n").map { |line| line + "\n" }
|
70
|
+
end
|
71
|
+
|
72
|
+
if action == :add
|
73
|
+
file_lines[tag_index] = "#{file_lines[tag_index].chomp} #{tag}\n"
|
74
|
+
elsif action == :remove
|
75
|
+
file_lines[tag_index].delete!(tag)
|
76
|
+
end
|
77
|
+
|
78
|
+
self.write_directives[file_path] = file_lines.join
|
79
|
+
|
80
|
+
new_tag = CukeModeler::Tag.new
|
81
|
+
new_tag.name = tag
|
82
|
+
test.tags << new_tag
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_tag?(test, tag)
|
87
|
+
test.tags.map(&:name).include?(tag)
|
88
|
+
end
|
89
|
+
|
90
|
+
def preview
|
91
|
+
unless self.write_directives.empty?
|
92
|
+
dirname = "robotag_preview"
|
93
|
+
FileUtils.rm_rf(dirname)
|
94
|
+
self.write_directives.each do |filepath, file_contents|
|
95
|
+
FileUtils.mkdir_p(File.dirname("#{dirname}/#{filepath}"))
|
96
|
+
File.open("#{dirname}/#{filepath}", 'w+') do |tmp_file|
|
97
|
+
tmp_file.print file_contents
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
33
103
|
def go!
|
34
|
-
self.
|
104
|
+
if !self.write_directives.empty?
|
105
|
+
self.write_directives.each do |file_path, joined_file_lines|
|
106
|
+
File.open(file_path, 'w+') { |file| file.print joined_file_lines }
|
107
|
+
end
|
108
|
+
else
|
109
|
+
self.chain_state
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def analysis_and_output(tag, action)
|
116
|
+
self.chain_state.map { |query_result| query_result[:self] }.each do |test|
|
117
|
+
if (test.is_a?(CukeModeler::Scenario) || test.is_a?(CukeModeler::Outline))
|
118
|
+
process_tag(test, tag, action)
|
119
|
+
else
|
120
|
+
raise("Unknown test type: #{test.class}")
|
121
|
+
end
|
122
|
+
end
|
35
123
|
end
|
36
124
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robotag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David West
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|