Skip to content

Commit

Permalink
Use start_with? and end_with? over Regexp matching and Regexp.escape
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Dec 3, 2016
1 parent f0e9719 commit daa3c66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/mspec/runner/mspec.rb
Expand Up @@ -347,16 +347,17 @@ def self.write_tag(tag)
# file if it is empty.
def self.delete_tag(tag)
deleted = false
pattern = /#{tag.tag}.*#{Regexp.escape(tag.escape(tag.description))}/
desc = tag.escape(tag.description)
file = tags_file
if File.exist? file
lines = IO.readlines(file)
File.open(file, "wb") do |f|
lines.each do |line|
unless pattern =~ line.chomp
f.puts line unless line.empty?
else
line = line.chomp
if line.start_with?(tag.tag) and line.end_with?(desc)
deleted = true
else
f.puts line unless line.empty?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/runner/mspec_spec.rb
Expand Up @@ -520,7 +520,7 @@
MSpec.delete_tag(@tag).should == true
MSpec.delete_tag(SpecTag.new("incomplete:The#best method ever")).should == true
MSpec.delete_tag(SpecTag.new("benchmark:The#fastest method today")).should == true
MSpec.delete_tag(SpecTag.new("extended:\"Multi-line\ntext\ntag\"")).should == true
MSpec.delete_tag(SpecTag.new('extended:"Multi-line\ntext\ntag"')).should == true
File.exist?(tmp("tags.txt", false)).should == false
end
end
Expand Down

0 comments on commit daa3c66

Please sign in to comment.