solve 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,273 @@
1
+ require 'spec_helper'
2
+
3
+ describe Solve::Graph do
4
+ subject { Solve::Graph.new }
5
+
6
+ describe "#artifacts" do
7
+ context "given a name and version argument" do
8
+ let(:name) { "nginx" }
9
+ let(:version) { "0.101.5" }
10
+
11
+ context "given the artifact of the given name and version does not exist" do
12
+ it "returns a Solve::Artifact" do
13
+ subject.artifacts(name, version).should be_a(Solve::Artifact)
14
+ end
15
+
16
+ it "the artifact has the given name" do
17
+ subject.artifacts(name, version).name.should eql(name)
18
+ end
19
+
20
+ it "the artifact has the given version" do
21
+ subject.artifacts(name, version).version.to_s.should eql(version)
22
+ end
23
+
24
+ it "adds an artifact to the artifacts collection" do
25
+ subject.artifacts(name, version)
26
+
27
+ subject.artifacts.should have(1).item
28
+ end
29
+
30
+ it "the artifact added matches the given name" do
31
+ subject.artifacts(name, version)
32
+
33
+ subject.artifacts[0].name.should eql(name)
34
+ end
35
+
36
+ it "the artifact added matches the given version" do
37
+ subject.artifacts(name, version)
38
+
39
+ subject.artifacts[0].version.to_s.should eql(version)
40
+ end
41
+ end
42
+ end
43
+
44
+ context "given no arguments" do
45
+ it "returns an array" do
46
+ subject.artifacts.should be_a(Array)
47
+ end
48
+
49
+ it "returns an empty array if no artifacts have been accessed" do
50
+ subject.artifacts.should have(0).items
51
+ end
52
+
53
+ it "returns an array containing an artifact if one was accessed" do
54
+ subject.artifacts("nginx", "0.101.5")
55
+
56
+ subject.artifacts.should have(1).item
57
+ end
58
+ end
59
+
60
+ context "given an unexpected number of arguments" do
61
+ it "raises an ArgumentError if more than two are provided" do
62
+ lambda {
63
+ subject.artifacts(1, 2, 3)
64
+ }.should raise_error(ArgumentError, "Unexpected number of arguments. You gave: 3. Expected: 0 or 2.")
65
+ end
66
+
67
+ it "raises an ArgumentError if one argument is provided" do
68
+ lambda {
69
+ subject.artifacts(nil)
70
+ }.should raise_error(ArgumentError, "Unexpected number of arguments. You gave: 1. Expected: 0 or 2.")
71
+ end
72
+
73
+ it "raises an ArgumentError if one of the arguments provided is nil" do
74
+ lambda {
75
+ subject.artifacts("nginx", nil)
76
+ }.should raise_error(ArgumentError, 'A name and version must be specified. You gave: ["nginx", nil].')
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#add_artifact" do
82
+ let(:artifact) { double('artifact', name: "nginx", version: "1.0.0") }
83
+
84
+ it "adds a Solve::Artifact to the collection of artifacts" do
85
+ subject.add_artifact(artifact)
86
+
87
+ subject.should have_artifact(artifact)
88
+ subject.artifacts.should have(1).item
89
+ end
90
+
91
+ it "should not add the same artifact twice to the collection" do
92
+ subject.add_artifact(artifact)
93
+ subject.add_artifact(artifact)
94
+
95
+ subject.artifacts.should have(1).item
96
+ end
97
+ end
98
+
99
+ describe "#remove_artifact" do
100
+ let(:artifact) { double('artifact', name: "nginx", version: "1.0.0") }
101
+
102
+ context "given the artifact is a member of the collection" do
103
+ before(:each) { subject.add_artifact(artifact) }
104
+
105
+ it "removes the Solve::Artifact from the collection of artifacts" do
106
+ subject.remove_artifact(artifact)
107
+
108
+ subject.artifacts.should have(0).items
109
+ end
110
+
111
+ it "returns the removed Solve::Artifact" do
112
+ subject.remove_artifact(artifact).should eql(artifact)
113
+ end
114
+ end
115
+
116
+ context "given the artifact is not a member of the collection" do
117
+ it "should return nil" do
118
+ subject.remove_artifact(artifact).should be_nil
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "#has_artifact?" do
124
+ let(:artifact) { double('artifact', name: "nginx", version: "1.0.0") }
125
+
126
+ it "returns true if the given Solve::Artifact is a member of the collection" do
127
+ subject.add_artifact(artifact)
128
+
129
+ subject.has_artifact?(artifact).should be_true
130
+ end
131
+
132
+ it "returns false if the given Solve::Artifact is not a member of the collection" do
133
+ subject.has_artifact?(artifact).should be_false
134
+ end
135
+ end
136
+
137
+ describe "#demands" do
138
+ context "given a name and constraint argument" do
139
+ let(:name) { "nginx" }
140
+ let(:constraint) { "~> 0.101.5" }
141
+
142
+ context "given the artifact of the given name and constraint does not exist" do
143
+ it "returns a Solve::Demand" do
144
+ subject.demands(name, constraint).should be_a(Solve::Demand)
145
+ end
146
+
147
+ it "the artifact has the given name" do
148
+ subject.demands(name, constraint).name.should eql(name)
149
+ end
150
+
151
+ it "the artifact has the given constraint" do
152
+ subject.demands(name, constraint).constraint.to_s.should eql(constraint)
153
+ end
154
+
155
+ it "adds an artifact to the demands collection" do
156
+ subject.demands(name, constraint)
157
+
158
+ subject.demands.should have(1).item
159
+ end
160
+
161
+ it "the artifact added matches the given name" do
162
+ subject.demands(name, constraint)
163
+
164
+ subject.demands[0].name.should eql(name)
165
+ end
166
+
167
+ it "the artifact added matches the given constraint" do
168
+ subject.demands(name, constraint)
169
+
170
+ subject.demands[0].constraint.to_s.should eql(constraint)
171
+ end
172
+ end
173
+ end
174
+
175
+ context "given only a name argument" do
176
+ it "returns a demand with a match all version constraint (>= 0.0.0)" do
177
+ subject.demands("nginx").constraint.to_s.should eql(">= 0.0.0")
178
+ end
179
+ end
180
+
181
+ context "given no arguments" do
182
+ it "returns an array" do
183
+ subject.demands.should be_a(Array)
184
+ end
185
+
186
+ it "returns an empty array if no demands have been accessed" do
187
+ subject.demands.should have(0).items
188
+ end
189
+
190
+ it "returns an array containing a demand if one was accessed" do
191
+ subject.demands("nginx", "~> 0.101.5")
192
+
193
+ subject.demands.should have(1).item
194
+ end
195
+ end
196
+
197
+ context "given an unexpected number of arguments" do
198
+ it "raises an ArgumentError if more than two are provided" do
199
+ lambda {
200
+ subject.demands(1, 2, 3)
201
+ }.should raise_error(ArgumentError, "Unexpected number of arguments. You gave: 3. Expected: 2 or less.")
202
+ end
203
+
204
+ it "raises an ArgumentError if a name argument of nil is provided" do
205
+ lambda {
206
+ subject.demands(nil)
207
+ }.should raise_error(ArgumentError, "A name must be specified. You gave: [nil].")
208
+ end
209
+
210
+ it "raises an ArgumentError if a name and constraint argument are provided but name is nil" do
211
+ lambda {
212
+ subject.demands(nil, "= 1.0.0")
213
+ }.should raise_error(ArgumentError, 'A name must be specified. You gave: [nil, "= 1.0.0"].')
214
+ end
215
+ end
216
+ end
217
+
218
+ describe "#add_demand" do
219
+ let(:demand) { double('demand') }
220
+
221
+ it "adds a Solve::Artifact to the collection of artifacts" do
222
+ subject.add_demand(demand)
223
+
224
+ subject.should have_demand(demand)
225
+ subject.demands.should have(1).item
226
+ end
227
+
228
+ it "should not add the same demand twice to the collection" do
229
+ subject.add_demand(demand)
230
+ subject.add_demand(demand)
231
+
232
+ subject.demands.should have(1).item
233
+ end
234
+ end
235
+
236
+ describe "#remove_demand" do
237
+ let(:demand) { double('demand') }
238
+
239
+ context "given the demand is a member of the collection" do
240
+ before(:each) { subject.add_demand(demand) }
241
+
242
+ it "removes the Solve::Artifact from the collection of demands" do
243
+ subject.remove_demand(demand)
244
+
245
+ subject.demands.should have(0).items
246
+ end
247
+
248
+ it "returns the removed Solve::Artifact" do
249
+ subject.remove_demand(demand).should eql(demand)
250
+ end
251
+ end
252
+
253
+ context "given the demand is not a member of the collection" do
254
+ it "should return nil" do
255
+ subject.remove_demand(demand).should be_nil
256
+ end
257
+ end
258
+ end
259
+
260
+ describe "#has_demand?" do
261
+ let(:demand) { double('demand') }
262
+
263
+ it "returns true if the given Solve::Artifact is a member of the collection" do
264
+ subject.add_demand(demand)
265
+
266
+ subject.has_demand?(demand).should be_true
267
+ end
268
+
269
+ it "returns false if the given Solve::Artifact is not a member of the collection" do
270
+ subject.has_demand?(demand).should be_false
271
+ end
272
+ end
273
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Solve::Version do
4
+ subject { Solve::Version.new("1.0.0") }
5
+
6
+ describe "#to_s" do
7
+ it "returns a string containing the major.minor.patch" do
8
+ subject.to_s.should eql("1.0.0")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Solve do
4
+ describe "ClassMethods" do
5
+ subject { Solve }
6
+
7
+ describe "#it" do
8
+ it "returns nil if a solution does not exist" do
9
+ pending
10
+ end
11
+ end
12
+
13
+ describe "#it!" do
14
+ it "raises NoSolutionError if a solution does not exist" do
15
+ pending
16
+ end
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,278 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jamie Winsor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dep_selector
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: fuubar
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: spork
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: redcarpet
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: guard-rspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: guard-spork
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: guard-yard
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: coolline
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ description: A Ruby constraint solver
207
+ email:
208
+ - jamie@vialstudios.com
209
+ executables: []
210
+ extensions: []
211
+ extra_rdoc_files: []
212
+ files:
213
+ - .gitignore
214
+ - .rbenv-version
215
+ - Gemfile
216
+ - Guardfile
217
+ - LICENSE
218
+ - README.md
219
+ - Thorfile
220
+ - lib/solve.rb
221
+ - lib/solve/artifact.rb
222
+ - lib/solve/constraint.rb
223
+ - lib/solve/core_ext.rb
224
+ - lib/solve/core_ext/kernel.rb
225
+ - lib/solve/demand.rb
226
+ - lib/solve/dependency.rb
227
+ - lib/solve/errors.rb
228
+ - lib/solve/gem_version.rb
229
+ - lib/solve/graph.rb
230
+ - lib/solve/version.rb
231
+ - solve.gemspec
232
+ - spec/acceptance/solutions_spec.rb
233
+ - spec/spec_helper.rb
234
+ - spec/unit/solve/artifact_spec.rb
235
+ - spec/unit/solve/constraint_spec.rb
236
+ - spec/unit/solve/demand_spec.rb
237
+ - spec/unit/solve/dependency_spec.rb
238
+ - spec/unit/solve/graph_spec.rb
239
+ - spec/unit/solve/version_spec.rb
240
+ - spec/unit/solve_spec.rb
241
+ homepage: https://github.com/reset/solve
242
+ licenses: []
243
+ post_install_message:
244
+ rdoc_options: []
245
+ require_paths:
246
+ - lib
247
+ required_ruby_version: !ruby/object:Gem::Requirement
248
+ none: false
249
+ requirements:
250
+ - - ! '>='
251
+ - !ruby/object:Gem::Version
252
+ version: 1.9.1
253
+ required_rubygems_version: !ruby/object:Gem::Requirement
254
+ none: false
255
+ requirements:
256
+ - - ! '>='
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ segments:
260
+ - 0
261
+ hash: 1692611676791310100
262
+ requirements: []
263
+ rubyforge_project:
264
+ rubygems_version: 1.8.23
265
+ signing_key:
266
+ specification_version: 3
267
+ summary: A Ruby constraint solver
268
+ test_files:
269
+ - spec/acceptance/solutions_spec.rb
270
+ - spec/spec_helper.rb
271
+ - spec/unit/solve/artifact_spec.rb
272
+ - spec/unit/solve/constraint_spec.rb
273
+ - spec/unit/solve/demand_spec.rb
274
+ - spec/unit/solve/dependency_spec.rb
275
+ - spec/unit/solve/graph_spec.rb
276
+ - spec/unit/solve/version_spec.rb
277
+ - spec/unit/solve_spec.rb
278
+ has_rdoc: