tagfu 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tagfu/tagger.rb +22 -10
- data/lib/tagfu/version.rb +1 -1
- data/spec/tagger_spec.rb +41 -1
- metadata +1 -1
data/lib/tagfu/tagger.rb
CHANGED
@@ -54,32 +54,44 @@ module Tagfu
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def delete_all(lines)
|
57
|
-
lines_to_delete =
|
57
|
+
lines_to_delete = lines_to_delete(lines, "@")
|
58
|
+
delete_lines(lines, lines_to_delete)
|
59
|
+
end
|
60
|
+
|
61
|
+
def lines_to_delete(lines, regex)
|
62
|
+
tmp = []
|
58
63
|
lines.each_with_index do |line, index|
|
59
|
-
if line.match(
|
60
|
-
|
64
|
+
if line.match(/#{regex}/)
|
65
|
+
tmp << index
|
61
66
|
end
|
62
67
|
end
|
63
|
-
|
68
|
+
tmp
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_lines(lines, lines_to_delete)
|
72
|
+
lines_to_delete = lines_to_delete.sort
|
73
|
+
index_adjustment = 0
|
64
74
|
lines_to_delete.each do |line_index|
|
65
|
-
lines.delete_at(line_index -
|
66
|
-
|
75
|
+
lines.delete_at(line_index - index_adjustment)
|
76
|
+
index_adjustment += 1
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
80
|
def delete_tags(lines)
|
81
|
+
lines_to_delete = []
|
71
82
|
@delete_tags.each do |tag|
|
72
|
-
lines.each_with_index do |line,
|
83
|
+
lines.each_with_index do |line, line_index|
|
73
84
|
if only_tag?(line, tag)
|
74
|
-
|
85
|
+
lines_to_delete << line_index
|
75
86
|
else
|
76
|
-
indent = lines[
|
87
|
+
indent = lines[line_index][/^\s+/].to_s
|
77
88
|
line = line.strip
|
78
89
|
next if line.empty?
|
79
|
-
lines[
|
90
|
+
lines[line_index] = indent + line.chomp.split(' ').delete_if {|word| word.match(/#{tag}/)}.join(' ') + "\n" if line.match(/^@/)
|
80
91
|
end
|
81
92
|
end
|
82
93
|
end
|
94
|
+
delete_lines(lines, lines_to_delete.flatten)
|
83
95
|
end
|
84
96
|
|
85
97
|
def only_tag?(line, tag)
|
data/lib/tagfu/version.rb
CHANGED
data/spec/tagger_spec.rb
CHANGED
@@ -54,6 +54,33 @@ RSpec.configure do |config|
|
|
54
54
|
When I run it through the tagger
|
55
55
|
Then I see that the tag has been updated
|
56
56
|
""",
|
57
|
+
:two_tags_to_delete =>
|
58
|
+
"""
|
59
|
+
@smoke
|
60
|
+
@smoke
|
61
|
+
Feature: Two tags to delete in feature file
|
62
|
+
|
63
|
+
@wip
|
64
|
+
@wip
|
65
|
+
@wip
|
66
|
+
Scenario: sample story
|
67
|
+
Given I have a feature file with one tag
|
68
|
+
When I run it through the tagger
|
69
|
+
Then I see that the tag has been updated
|
70
|
+
""",
|
71
|
+
:two_tags_to_update =>
|
72
|
+
"""
|
73
|
+
@wip
|
74
|
+
@wip
|
75
|
+
Feature: Two tags to delete in feature file
|
76
|
+
|
77
|
+
@wip
|
78
|
+
@wip
|
79
|
+
Scenario: sample story
|
80
|
+
Given I have a feature file with one tag
|
81
|
+
When I run it through the tagger
|
82
|
+
Then I see that the tag has been updated
|
83
|
+
""",
|
57
84
|
:three_tags_delete_update =>
|
58
85
|
"""
|
59
86
|
Feature: Three tags to update in feature file
|
@@ -98,7 +125,6 @@ RSpec.configure do |config|
|
|
98
125
|
end
|
99
126
|
|
100
127
|
config.after(:all) do
|
101
|
-
#FileUtils.remove_entry_secure @dir
|
102
128
|
files = Dir.glob("*.feature")
|
103
129
|
files.each {|file| File.unlink(file)}
|
104
130
|
end
|
@@ -155,6 +181,20 @@ RSpec.configure do |config|
|
|
155
181
|
File.readlines(file).any? {|line| line =~ /@story3/}.should be_true
|
156
182
|
end
|
157
183
|
|
184
|
+
it "should delete duplicate tags in consecutive lines" do
|
185
|
+
file = "two_tags_to_delete.feature"
|
186
|
+
Tagfu::Tagger.new({:path => file, :delete_tags => ['@wip', '@smoke']}).get_files
|
187
|
+
File.readlines(file).any? {|line| line =~ /@smoke/}.should be_false
|
188
|
+
File.readlines(file).any? {|line| line =~ /@wip/}.should be_false
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should update duplicate tags in consecutive lines" do
|
192
|
+
file = "two_tags_to_update.feature"
|
193
|
+
Tagfu::Tagger.new({:path => file, :update_tags => ['@wip', '@smoke']}).get_files
|
194
|
+
File.readlines(file).any? {|line| line =~ /@wip/}.should be_false
|
195
|
+
File.readlines(file).any? {|line| line =~ /@smoke/}.should be_true
|
196
|
+
end
|
197
|
+
|
158
198
|
it "should delete all tags in feature file" do
|
159
199
|
file = "all_tags_delete.feature"
|
160
200
|
Tagfu::Tagger.new({:path => file, :delete_all => true}).get_files
|