Skip to content

Commit

Permalink
Allowing for null gemsets and null dependencies (avoid creating solo …
Browse files Browse the repository at this point in the history
…gem for every project)
  • Loading branch information
winton committed Jan 10, 2011
1 parent 74e369c commit da688ab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lib/gem_template/gems.rb
Expand Up @@ -72,10 +72,10 @@ def gemset=(gemset)
end

@versions = (@gemsets[gemspec.name.to_sym] || {}).inject({}) do |hash, (key, value)|
if !value.is_a?(::Hash)
if !value.is_a?(::Hash) && value
hash[key] = value
elsif key == @gemset
value.each { |k, v| hash[k] = v }
(value || {}).each { |k, v| hash[k] = v }
end
hash
end
Expand All @@ -88,9 +88,9 @@ def gemset=(gemset)

def gemset_names
(
[ :default, :solo ] +
[ :default ] +
@gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
array.push(key) if value.is_a?(::Hash)
array.push(key) if value.is_a?(::Hash) || value.nil?
array
}
).uniq
Expand All @@ -115,7 +115,7 @@ def deep_merge(first, second)
end

def dependency_filter(dependencies, match)
dependencies.inject([]) { |array, value|
(dependencies || []).inject([]) { |array, value|
if value.is_a?(::Hash)
array += value[match.to_s] if value[match.to_s]
else
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/gemsets.yml
Expand Up @@ -5,4 +5,5 @@ name:
rspec: =1.3.1
rspec2:
mysql2: =0.2.6
rspec: =2.3.0
rspec: =2.3.0
solo: null
8 changes: 1 addition & 7 deletions spec/fixtures/gemspec.yml
Expand Up @@ -12,10 +12,4 @@ dependencies:
- mysql
- rspec2:
- mysql2
development_dependencies:
- default:
- mysql
- rspec
- rspec2:
- mysql2
- rspec
development_dependencies: null
69 changes: 57 additions & 12 deletions spec/gem_template/gems_spec.rb
Expand Up @@ -64,7 +64,8 @@
:rspec2 => {
:mysql2 => "=0.2.6",
:rspec => "=2.3.0"
}
},
:solo => nil
}
}
end
Expand All @@ -80,7 +81,11 @@

it "should return proper values for Gems.dependencies" do
GemTemplate::Gems.dependencies.should == [ :rake, :mysql ]
GemTemplate::Gems.development_dependencies.should == [ :mysql, :rspec ]
GemTemplate::Gems.development_dependencies.should == []
end

it "should return proper values for Gems.gemset_names" do
GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end

Expand All @@ -105,7 +110,8 @@
:rspec2 => {
:mysql2=>"=0.2.6",
:rspec => "=2.3.0"
}
},
:solo => nil
}
}
end
Expand All @@ -120,7 +126,52 @@

it "should return proper values for Gems.dependencies" do
GemTemplate::Gems.dependencies.should == [ :rake, :mysql2 ]
GemTemplate::Gems.development_dependencies.should == [ :mysql2, :rspec ]
GemTemplate::Gems.development_dependencies.should == []
end

it "should return proper values for Gems.gemset_names" do
GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end

describe :solo do
before(:each) do
GemTemplate::Gems.gemset = :solo
end

it "should set @gemset" do
GemTemplate::Gems.gemset.should == :solo
end

it "should set @gemsets" do
GemTemplate::Gems.gemsets.should == {
:name => {
:rake => ">0.8.6",
:default => {
:externals => '=1.0.2',
:mysql => "=2.8.1",
:rspec => "=1.3.1"
},
:rspec2 => {
:mysql2=>"=0.2.6",
:rspec => "=2.3.0"
},
:solo => nil
}
}
end

it "should set Gems.versions" do
GemTemplate::Gems.versions.should == {:rake=>">0.8.6"}
end

it "should return proper values for Gems.dependencies" do
GemTemplate::Gems.dependencies.should == [:rake]
GemTemplate::Gems.development_dependencies.should == []
end

it "should return proper values for Gems.gemset_names" do
GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end

Expand Down Expand Up @@ -168,10 +219,7 @@
{ "default" => [ "mysql" ] },
{ "rspec2" => [ "mysql2" ] }
],
"development_dependencies" => [
{ "default" => [ "mysql", "rspec" ] },
{ "rspec2" => [ "mysql2", "rspec" ] }
]
"development_dependencies" => nil
}
end

Expand All @@ -188,10 +236,7 @@
{ "default" => ["mysql"] },
{ "rspec2" => [ "mysql2" ] }
]
GemTemplate::Gems.gemspec.development_dependencies.should == [
{ "default" => [ "mysql", "rspec" ] },
{ "rspec2" => [ "mysql2", "rspec" ] }
]
GemTemplate::Gems.gemspec.development_dependencies.should == nil
end

it "should produce a valid gemspec" do
Expand Down

0 comments on commit da688ab

Please sign in to comment.