Fix acceptance tests to actually remove gems
This commit is contained in:
parent
bbd0d5ed25
commit
021d3d6ec8
|
@ -35,7 +35,7 @@ module Tests
|
|||
|
||||
def remove_gem(gem)
|
||||
updating do
|
||||
fs.remove_from_file('Gemfile', /^gem ("|')gem\1/)
|
||||
fs.comment_lines_matching('Gemfile', /^[ ]*gem ("|')#{gem}\1/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -69,9 +69,32 @@ module Tests
|
|||
end
|
||||
|
||||
def remove_from_file(path, pattern)
|
||||
unless pattern.is_a?(Regexp)
|
||||
pattern = Regexp.new('^' + Regexp.escape(pattern) + '$')
|
||||
end
|
||||
|
||||
transform(path) do |lines|
|
||||
lines.reject { |line| line =~ pattern }
|
||||
end
|
||||
end
|
||||
|
||||
def comment_lines_matching(path, pattern)
|
||||
transform(path) do |lines|
|
||||
lines.map do |line|
|
||||
if line =~ pattern
|
||||
"###{line}"
|
||||
else
|
||||
line
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def transform(path)
|
||||
content = read(path)
|
||||
content.sub!(/#{pattern}\n/, '')
|
||||
write(path, content)
|
||||
lines = content.split(/\n/)
|
||||
transformed_lines = yield lines
|
||||
write(path, transformed_lines.join("\n") + "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue