Skip to content

Commit

Permalink
Fix acceptance tests to actually remove gems
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Feb 5, 2015
1 parent bbd0d5e commit 021d3d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/support/tests/bundle.rb
Expand Up @@ -35,7 +35,7 @@ def add_gem(gem, *args)

def remove_gem(gem)
updating do
fs.remove_from_file('Gemfile', /^gem ("|')gem\1/)
fs.comment_lines_matching('Gemfile', /^[ ]*gem ("|')#{gem}\1/)
end
end

Expand Down
27 changes: 25 additions & 2 deletions spec/support/tests/filesystem.rb
Expand Up @@ -69,9 +69,32 @@ def append_to_file(path, content, options = {})
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

0 comments on commit 021d3d6

Please sign in to comment.