spec/acceptance/solutions_spec.rb in solve-0.6.1 vs spec/acceptance/solutions_spec.rb in solve-0.7.0
- old
+ new
@@ -1,9 +1,8 @@
require 'spec_helper'
describe "Solutions" do
-
it "chooses the correct artifact for the demands" do
graph = Solve::Graph.new
graph.artifacts("mysql", "2.0.0")
graph.artifacts("mysql", "1.2.0")
graph.artifacts("nginx", "1.0.0").depends("mysql", "= 1.2.0")
@@ -188,7 +187,72 @@
"get-the-old-one" => "1.0.0",
"locked-mid-1" => "2.0.0",
"locked-mid-2" => "1.0.0",
"old-bottom" => "2.0.0"
})
+ end
+
+ describe "when options[:sorted] is true" do
+ describe "with a simple list of dependencies" do
+ it "returns a sorted list of dependencies" do
+ graph = Solve::Graph.new
+
+ graph.artifacts("A", "1.0.0").depends("B", "= 1.0.0")
+ graph.artifacts("B", "1.0.0").depends("C", "= 1.0.0")
+ graph.artifacts("C", "1.0.0")
+
+ demands = [["A"]]
+
+ result = Solve.it!(graph, demands, { :sorted => true })
+
+ result.should eql([
+ ["C", "1.0.0"],
+ ["B", "1.0.0"],
+ ["A", "1.0.0"]
+ ])
+ end
+ end
+
+ # The order that the demands come in determines the order of artifacts
+ # in the solver's variable_table. This must not determine the sort order
+ describe "with a constraint that depends upon an earlier constrained artifact" do
+ it "returns a sorted list of dependencies" do
+ graph = Solve::Graph.new
+
+ graph.artifacts("B", "1.0.0").depends("A", "= 1.0.0")
+ graph.artifacts("A", "1.0.0").depends("C", "= 1.0.0")
+ graph.artifacts("C", "1.0.0")
+
+ demands = [["A"],["B"]]
+
+ result = Solve.it!(graph, demands, { :sorted => true } )
+
+ result.should eql([
+ ["C", "1.0.0"],
+ ["A", "1.0.0"],
+ ["B", "1.0.0"]
+ ])
+ end
+ end
+
+ describe "when the solution is cyclic" do
+ it "raises a Solve::Errors::UnsortableSolutionError which contains the unsorted solution" do
+ graph = Solve::Graph.new
+
+ graph.artifacts("A", "1.0.0").depends("B", "= 1.0.0")
+ graph.artifacts("B", "1.0.0").depends("C", "= 1.0.0")
+ graph.artifacts("C", "1.0.0").depends("A", "= 1.0.0")
+
+ demands = [["A"]]
+
+ expect { Solve.it!(graph, demands, { :sorted => true } ) }.to raise_error { |error|
+ error.should be_a(Solve::Errors::UnsortableSolutionError)
+ error.unsorted_solution.should eql({
+ "A" => "1.0.0",
+ "B" => "1.0.0",
+ "C" => "1.0.0",
+ })
+ }
+ end
+ end
end
end