Permalink
Browse files

Fixes two bugs:

First, dependencies of dependencies now install. (oops, sorry about that one!)
Second, the help now works when a parameter count assertion fails.
  • Loading branch information...
1 parent c7aadbc commit 6bfcc3978b55e7df863ccdae1cc1e0f0e601cf38 @brendanjerwin brendanjerwin committed Oct 1, 2010
View
15 features/dependency_leveling/dependency_version_overlap.feature
@@ -52,4 +52,17 @@ Scenario: Conflict is with a package that is not a dependency itself in the lib
When package "interloper (2.0.0)" is proposed
Then a conflict should be detected
And the conflicting package should be "explicit" between "= 1.0.0" and ">= 1.0.1, <= 1.4.0"
-
+
+Scenario: Propose a package with dependencies that have dependencies
+ Given package "bottom (1.0.0)" exists
+ And package "middle (1.0.0)" exists and depends on:
+ | name | constraint |
+ | bottom | = 1.0.0 |
+ And package "top (1.0.0)" exists and depends on:
+ | name | constraint |
+ | middle | = 1.0.0 |
+ When package "top (1.0.0)" is proposed
+ Then a conflict should not be detected
+ And the suggested version for package "top" should be "= 1.0.0"
+ And the suggested version for package "middle" should be "= 1.0.0"
+ And the suggested version for package "bottom" should be "= 1.0.0"
View
19 features/dependency_leveling/step_definitions/dependency_leveling.rb
@@ -2,18 +2,13 @@
require 'lib/nu/dependency_leveling/package_conflict_overlap_resolver'
Given /^I am talking about the ([^"]*)$/ do |class_name|
- case class_name
- when "PackageConflictOverlapResolver"
- @leveler_maker = lambda do
- def @packages.find(name)
- self.select{|spec| spec.name == name}
- end
- PackageConflictOverlapResolver.new(@installed_packages, @packages)
- end
- else
- @leveler_maker = lambda{Kernel.const_get(class_name).new(@installed_packages)}
+ @packages = []
+ def @packages.find(name, constraint=nil)
+ return self.select{|spec| spec.name == name} unless constraint
+ return self.select{|spec| spec.satisfies_requirement?(Gem::Dependency.new(name, constraint))}.first if constraint
end
-
+ @packages.should respond_to('find')
+ @leveler_maker = lambda{Kernel.const_get(class_name).new(@installed_packages, @packages)}
end
def existing_package(name, version)
@@ -26,11 +21,11 @@ def existing_package(name, version)
end
When /^package "([^"]*) \((\d\.\d\.\d)\)" is proposed$/ do |name, version|
+ @installed_packages ||= []
leveler = @leveler_maker.call
@result = leveler.analyze_proposal(existing_package(name, version))
end
-
Then /^a conflict should be detected$/ do
@result.conflict?.should be_true
end
View
1 features/dependency_leveling/step_definitions/package_creation.rb
@@ -14,7 +14,6 @@
end
def create_package(name, version)
- @packages ||= []
spec = Gem::Specification.new do |s|
s.name = name
s.version = version
View
8 lib/nu/app.rb
@@ -24,7 +24,8 @@ def initialize(arguments, stdin, stdout)
@commands = []
@arguments = arguments
-
+ @help_command = lambda{output_help}
+
Nu::Api.set_log(lambda {|msg| log msg})
Nu::Api.set_out(lambda {|msg| disp msg})
@shim = CliShim.new(lambda {|msg| disp msg}, lambda {|msg| log msg})
@@ -59,8 +60,6 @@ def initialize(arguments, stdin, stdout)
output_help
end
- @help_command = lambda{output_help}
-
end.parse!
rescue
@commands << @help_command
@@ -141,7 +140,8 @@ def extract_commands
def assert_param_count(count)
unless @arguments.length == count
- @help_command.call
+ @commands << @help_command
+ execute_commands
end
end
View
14 lib/nu/dependency_leveling/package_conflict_finder.rb
@@ -2,7 +2,9 @@
require File.expand_path(File.dirname(__FILE__) + "/analysis_results.rb")
class PackageConflictFinder
- def initialize(installed_packages)
+ def initialize(installed_packages, package_lister)
+ raise "package_lister must respond to find(name, version)" unless package_lister.respond_to?("find")
+ @package_lister = package_lister
@installed_packages = installed_packages
end
@@ -34,12 +36,18 @@ def initialized_suggested_packages(proposed_package)
suggested_packages.reject! {|i| i[:name] == proposed_package.name}
suggested_packages << {:name=>proposed_package.name, :version=> req(proposed_package.version)}
- proposed_package.dependencies.each do |dep|
+ extract_dependencies(proposed_package, suggested_packages)
+
+ return suggested_packages
+ end
+
+ def extract_dependencies(package, suggested_packages)
+ package.dependencies.each do |dep|
unless suggested_packages.any?{|i| i[:name] == dep.name}
suggested_packages << {:name=>dep.name, :version=>dep.requirement}
+ extract_dependencies(@package_lister.find(dep.name, dep.requirement), suggested_packages)
end
end
- return suggested_packages
end
def find_conflicts(proposed_spec)
View
3 lib/nu/dependency_leveling/package_conflict_overlap_resolver.rb
@@ -3,10 +3,9 @@
class PackageConflictOverlapResolver
def initialize(installed_packages, package_lister)
+ @conflict_finder = PackageConflictFinder.new(installed_packages, package_lister)
@installed_packages = installed_packages
- raise "package_lister must respond to find(name)" unless package_lister.respond_to?("find")
@package_lister = package_lister
- @conflict_finder = PackageConflictFinder.new(installed_packages)
end
def analyze_proposal(proposed_package)
View
5 lib/nu/gem_tools.rb
@@ -11,7 +11,7 @@ def dependency_from_requirement(spec, requirement)
Gem::Dependency.new(spec,requirement)
end
- def find(package_name)
+ def find(package_name, requirement=nil)
dependency = dependency_from_requirement(package_name, nil)
fetcher = Gem::SpecFetcher.new
specs = fetcher.fetch(dependency, true)
@@ -21,7 +21,8 @@ def find(package_name)
end
specs.sort! {|a,b| b.version <=> a.version}
end
- specs
+ return specs unless requirement
+ return specs.detect {|spec| spec.satisfies_requirement?(dependency)} if requirement
end
def remote_spec_for(spec, requirement=nil)

0 comments on commit 6bfcc39

Please sign in to comment.