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

6 changes: 5 additions & 1 deletion lib/appraisal/bundler_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def run(&block)
end

def gem(name, *requirements)
@dependencies.add(name, substitute_git_source(requirements))
if requirements.include?(:remove)
jebentier marked this conversation as resolved.
Show resolved Hide resolved
@dependencies.remove(name)
else
@dependencies.add(name, substitute_git_source(requirements))
end
end

def group(*names, &block)
Expand Down
11 changes: 10 additions & 1 deletion lib/appraisal/dependency_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

describe 'Appraisals file Bundler DSL compatibility' do
it 'supports all Bundler DSL in Appraisals file' do
build_gems %w(bagel orange_juice milk waffle coffee ham sausage pancake)
build_gems %w(bagel orange_juice milk waffle coffee ham
sausage pancake rotten_egg)
build_git_gems %w(egg croissant pain_au_chocolat omelette)

build_gemfile <<-Gemfile
Expand All @@ -24,6 +25,7 @@
group :breakfast do
gem 'orange_juice'
gem "omelette", :custom_git_source => "omelette"
gem 'rotten_egg'
end

platforms :ruby, :jruby do
Expand Down Expand Up @@ -58,6 +60,7 @@
end

group :breakfast do
gem 'rotten_egg', :remove
jebentier marked this conversation as resolved.
Show resolved Hide resolved
gem 'bacon'

platforms :rbx do
Expand Down
19 changes: 19 additions & 0 deletions spec/appraisal/dependency_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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