-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.rb
More file actions
45 lines (38 loc) · 880 Bytes
/
Copy pathsample.rb
File metadata and controls
45 lines (38 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Version
include Comparable
attr_reader :major, :minor, :patch
def initialize(version)
@major, @minor, @patch =
version.split('.').map(&:to_i)
end
def <=>(other)
return nil unless other.is_a?(Version)
[major <=> other.major,
minor <=> other.minor,
patch <=> other.patch,
].detect {|n| !n.zero?} || 0
end
end
require 'minitest/autorun'
describe(Version) do
describe("when parsing") do
before do
@version = Version.new('10.8.9')
end
it("creates three integers") do
@version.major.must_equal(10)
@version.minor.must_equal(8)
@version.patch.must_equal(9)
end
end
describe("when comparing") do
before do
@v1 = Version.new("2.1.1")
@v2 = Version.new("2.3.0")
end
it("orders correctly") do
@v1.wont_equal(@v2)
@v1.must_be(:<, @v2)
end
end
end