Fix acceptance tests to actually remove gems

This commit is contained in:
Elliot Winkler 2015-02-05 00:01:02 -07:00
parent bbd0d5ed25
commit 021d3d6ec8
2 changed files with 26 additions and 3 deletions

View File

@ -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

View File

@ -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