From 021d3d6ec8d9fb8f5613a60ce863d445779e5f2a Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 5 Feb 2015 00:01:02 -0700 Subject: [PATCH] Fix acceptance tests to actually remove gems --- spec/support/tests/bundle.rb | 2 +- spec/support/tests/filesystem.rb | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/spec/support/tests/bundle.rb b/spec/support/tests/bundle.rb index d659860c3..74f6b2d92 100644 --- a/spec/support/tests/bundle.rb +++ b/spec/support/tests/bundle.rb @@ -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 diff --git a/spec/support/tests/filesystem.rb b/spec/support/tests/filesystem.rb index 1afac4790..fd8bbe34d 100644 --- a/spec/support/tests/filesystem.rb +++ b/spec/support/tests/filesystem.rb @@ -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