Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#170) Add ability to remove gem from appraisal #171

Next Next commit
Add the ability to remove a dependency from the dependency list
jebentier committed Oct 6, 2020

Verified

This commit was signed with the committer’s verified signature.
djhi Gildas Garcia
commit 6794411286cf8b5078bdb460e53394fca944f4d1
11 changes: 10 additions & 1 deletion lib/appraisal/dependency_list.rb
Original file line number Diff line number Diff line change
@@ -4,10 +4,19 @@ module Appraisal
class DependencyList
def initialize
@dependencies = Hash.new
@removed_dependencies = Set.new
end

def add(name, requirements)
@dependencies[name] = Dependency.new(name, requirements)
unless @removed_dependencies.include?(name)
@dependencies[name] = Dependency.new(name, requirements)
end
end

def remove(name)
if @removed_dependencies.add?(name)
@dependencies.delete(name)
end
end

def to_s
19 changes: 19 additions & 0 deletions spec/appraisal/dependency_list_spec.rb
Original file line number Diff line number Diff line change
@@ -28,4 +28,23 @@
expect(dependency_list.to_s).to eq %(gem "rails", "4.1.4")
end
end

describe "#remove" do
let(:dependency_list) { Appraisal::DependencyList.new }

before do
dependency_list.add("rails", ["4.1.4"])
end

it "removes the dependency from the list" do
dependency_list.remove("rails")
expect(dependency_list.to_s).to eq("")
end

it "respects the removal over an addition" do
dependency_list.remove("rails")
dependency_list.add("rails", ["4.1.0"])
expect(dependency_list.to_s).to eq("")
end
end
end