semantic 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d064086ebe8f746d56e7f03e1897210d3ffbebd
4
- data.tar.gz: d3ca4b76c52dc700d6ffeec7a0fe2feda43d4e73
3
+ metadata.gz: 25912a3ae732b9bee108db7982c3c32a8970579c
4
+ data.tar.gz: fcd186042df03126f0318442f62e8eccc0b726d6
5
5
  SHA512:
6
- metadata.gz: be0225ee57be527639197377e7f97872166f5fb34d931d2fd56044fbb390c180e26116f266f94f61603e89bb76d94380242bb2998125ab80b913036a92e1f4d9
7
- data.tar.gz: 53a92041fd0d46b7820c86156524d09693fa992c55826d040b1876b132851c1f47e4e639f87f13f4a580b74a89fceeb64ab701a542437fbd817e004217e68d3d
6
+ metadata.gz: b3bf5332d05f69d77d1e04889d2782b201c8c8e1215854abcf5c695cf46793bcf013f5c901707683429989585c155f1111bcd0ad55504db3f865ffbdc1de6636
7
+ data.tar.gz: 3bedeefba2d4579b5bc262f9b09efa2b7ab625b4b715feb6059f93fced4661632ca037d62686da05c4f2f0527f07bbefd80ee2ae47cb835c0675ccf37b3637d1
@@ -1,5 +1,4 @@
1
1
  module Semantic
2
- GEM_VERSION = '1.4.1'
2
+ GEM_VERSION = '1.5.0'
3
3
  autoload :Version, 'semantic/version'
4
4
  end
5
-
@@ -1,29 +1,54 @@
1
1
  # See: http://semver.org
2
2
  module Semantic
3
3
  class Version
4
- SemVerRegexp = /\A(\d+\.\d+\.\d+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?\Z/
5
- attr_accessor :major, :minor, :patch, :pre, :build
4
+ SemVerRegexp = /\A(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?\Z/
6
5
 
7
- def initialize version_str
8
- raise ArgumentError.new("#{version_str} is not a valid SemVer Version (http://semver.org)") unless version_str =~ SemVerRegexp
9
6
 
10
- version, parts = version_str.split '-'
11
- if not parts.nil? and parts.include? '+'
12
- @pre, @build = parts.split '+'
13
- elsif version.include? '+'
14
- version, @build = version.split '+'
15
- else
16
- @pre = parts
17
- end
7
+ attr_accessor :major, :minor, :patch, :pre, :build
18
8
 
9
+ def initialize version_str
10
+ v = version_str.match(SemVerRegexp)
19
11
 
20
- @major, @minor, @patch = version.split('.').map(&:to_i)
12
+ raise ArgumentError.new("#{version_str} is not a valid SemVer Version (http://semver.org)") if v.nil?
13
+ @major = v[1].to_i
14
+ @minor = v[2].to_i
15
+ @patch = v[3].to_i
16
+ @pre = v[4]
17
+ @build = v[5]
18
+ @version = version_str
21
19
  end
22
20
 
21
+
23
22
  def build=(b)
24
23
  @build = (!b.nil? && b.empty?) ? nil : b
25
24
  end
26
25
 
26
+ def identifiers(pre)
27
+ array = pre.split(".")
28
+ array.each_with_index {|e,i| array[i] = Integer(e) if /\A\d+\z/.match(e)}
29
+ return array
30
+ end
31
+
32
+ def compare_pre(prea, preb)
33
+ if prea.nil? || preb.nil?
34
+ return 0 if prea.nil? && preb.nil?
35
+ return 1 if prea.nil?
36
+ return -1 if preb.nil?
37
+ end
38
+ a = identifiers(prea)
39
+ b = identifiers(preb)
40
+ smallest = a.size < b.size ? a : b
41
+ smallest.each_with_index do |e, i|
42
+ c = a[i] <=> b[i]
43
+ if c.nil?
44
+ return a[i].is_a?(Integer) ? -1 : 1
45
+ elsif c != 0
46
+ return c
47
+ end
48
+ end
49
+ return a.size <=> b.size
50
+ end
51
+
27
52
  def to_a
28
53
  [@major, @minor, @patch, @pre, @build]
29
54
  end
@@ -32,7 +57,6 @@ module Semantic
32
57
  str = [@major, @minor, @patch].join '.'
33
58
  str << '-' << @pre unless @pre.nil?
34
59
  str << '+' << @build unless @build.nil?
35
-
36
60
  str
37
61
  end
38
62
 
@@ -45,19 +69,23 @@ module Semantic
45
69
  alias to_array to_a
46
70
  alias to_string to_s
47
71
 
48
- def <=> other_version
49
- other_version = Version.new(other_version) if other_version.is_a? String
50
-
51
- v1 = self.dup
52
- v2 = other_version.dup
72
+ def hash
73
+ to_a.hash
74
+ end
53
75
 
54
- # The build must be excluded from the comparison, so that e.g. 1.2.3+foo and 1.2.3+bar are semantically equal.
55
- # "Build metadata SHOULD be ignored when determining version precedence".
56
- # (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
57
- v1.build = nil
58
- v2.build = nil
76
+ def eql? other_version
77
+ self.hash == other_version.hash
78
+ end
59
79
 
60
- compare_recursively(v1.to_a, v2.to_a)
80
+ def <=> other_version
81
+ other_version = Version.new(other_version) if other_version.is_a? String
82
+ [:major, :minor, :patch].each do |part|
83
+ c = (self.send(part) <=> other_version.send(part))
84
+ if c != 0
85
+ return c
86
+ end
87
+ end
88
+ return compare_pre(self.pre, other_version.pre)
61
89
  end
62
90
 
63
91
  def > other_version
@@ -103,6 +131,7 @@ module Semantic
103
131
  end
104
132
 
105
133
  def increment!(term)
134
+ term = term.to_sym
106
135
  new_version = clone
107
136
  new_value = send(term) + 1
108
137
 
@@ -138,30 +167,5 @@ module Semantic
138
167
  end
139
168
  end
140
169
 
141
- def compare_recursively ary1, ary2
142
- # Short-circuit the recursion entirely if they're just equal
143
- return 0 if ary1 == ary2
144
-
145
- a = ary1.shift; b = ary2.shift
146
-
147
- # Reached the end of the arrays, equal all the way down
148
- return 0 if a.nil? and b.nil?
149
-
150
- # Mismatched types (ie. one has a pre and the other doesn't)
151
- if a.nil? and not b.nil?
152
- return 1
153
- elsif not a.nil? and b.nil?
154
- return -1
155
- end
156
-
157
- if a < b
158
- return -1
159
- elsif a > b
160
- return 1
161
- end
162
-
163
- # Versions are equal thus far, so recurse down to the next part.
164
- compare_recursively ary1, ary2
165
- end
166
170
  end
167
171
  end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'semantic/core_ext'
3
3
 
4
+ # rubocop:disable Metrics/BlockLength
4
5
  describe 'Core Extensions' do
5
- context "String#to_version" do
6
+ context 'String#to_version' do
6
7
  before(:each) do
7
8
  @test_versions = [
8
9
  '1.0.0',
@@ -23,20 +24,23 @@ describe 'Core Extensions' do
23
24
  ]
24
25
  end
25
26
 
26
- it "extends String with a #to_version method" do
27
- String.new.should respond_to(:to_version)
27
+ it 'extends String with a #to_version method' do
28
+ expect('').to respond_to(:to_version)
28
29
  end
29
30
 
30
- it "converts the String into a Version object" do
31
+ it 'converts the String into a Version object' do
31
32
  @test_versions.each do |v|
32
- expect { v.to_version }.to_not raise_error()
33
- v.to_version.should be_a(Semantic::Version)
33
+ expect { v.to_version }.to_not raise_error
34
+ expect(v.to_version).to be_a(Semantic::Version)
34
35
  end
35
36
  end
36
37
 
37
- it "raises an error on invalid strings" do
38
+ it 'raises an error on invalid strings' do
38
39
  @bad_versions.each do |v|
39
- expect { v.to_version }.to raise_error()
40
+ expect { v.to_version }.to raise_error(
41
+ ArgumentError,
42
+ /not a valid SemVer/
43
+ )
40
44
  end
41
45
  end
42
46
  end
@@ -8,7 +8,6 @@ RSpec.configure do |config|
8
8
  require 'semantic'
9
9
 
10
10
  config.mock_framework = :rspec
11
- config.treat_symbols_as_metadata_keys_with_true_values = true
12
11
  config.run_all_when_everything_filtered = true
13
12
  config.filter_run :focus
14
13
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
-
2
+ # rubocop:disable Metrics/BlockLength, Style/VariableNumber
3
3
  describe Semantic::Version do
4
4
  before(:each) do
5
5
  @test_versions = [
@@ -22,63 +22,66 @@ describe Semantic::Version do
22
22
  ]
23
23
  end
24
24
 
25
- context "parsing" do
26
- it "parses valid SemVer versions" do
25
+ context 'parsing' do
26
+ it 'parses valid SemVer versions' do
27
27
  @test_versions.each do |v|
28
- expect { Semantic::Version.new v }.to_not raise_error()
28
+ expect { Semantic::Version.new v }.not_to raise_error
29
29
  end
30
30
  end
31
31
 
32
- it "raises an error on invalid versions" do
32
+ it 'raises an error on invalid versions' do
33
33
  @bad_versions.each do |v|
34
- expect { Semantic::Version.new v }.to raise_error()
34
+ expect { Semantic::Version.new v }.to raise_error(
35
+ ArgumentError,
36
+ /not a valid SemVer/
37
+ )
35
38
  end
36
39
  end
37
40
 
38
- it "stores parsed versions in member variables" do
41
+ it 'stores parsed versions in member variables' do
39
42
  v1 = Semantic::Version.new '1.5.9'
40
- v1.major.should == 1
41
- v1.minor.should == 5
42
- v1.patch.should == 9
43
- v1.pre.should be_nil
44
- v1.build.should be_nil
43
+ expect(v1.major).to eq(1)
44
+ expect(v1.minor).to eq(5)
45
+ expect(v1.patch).to eq(9)
46
+ expect(v1.pre).to be_nil
47
+ expect(v1.build).to be_nil
45
48
 
46
49
  v2 = Semantic::Version.new '0.0.1-pre.1'
47
- v2.major.should == 0
48
- v2.minor.should == 0
49
- v2.patch.should == 1
50
- v2.pre.should == 'pre.1'
51
- v2.build.should be_nil
50
+ expect(v2.major).to eq(0)
51
+ expect(v2.minor).to eq(0)
52
+ expect(v2.patch).to eq(1)
53
+ expect(v2.pre).to eq('pre.1')
54
+ expect(v2.build).to be_nil
52
55
 
53
56
  v3 = Semantic::Version.new '1.0.1-pre.5+build.123.5'
54
- v3.major.should == 1
55
- v3.minor.should == 0
56
- v3.patch.should == 1
57
- v3.pre.should == 'pre.5'
58
- v3.build.should == 'build.123.5'
57
+ expect(v3.major).to eq(1)
58
+ expect(v3.minor).to eq(0)
59
+ expect(v3.patch).to eq(1)
60
+ expect(v3.pre).to eq('pre.5')
61
+ expect(v3.build).to eq('build.123.5')
59
62
 
60
63
  v4 = Semantic::Version.new '0.0.0+hello'
61
- v4.major.should == 0
62
- v4.minor.should == 0
63
- v4.patch.should == 0
64
- v4.pre.should be_nil
65
- v4.build.should == 'hello'
66
- end
67
-
68
- it "provides round-trip fidelity for an empty build parameter" do
69
- v = Semantic::Version.new("1.2.3")
70
- v.build = ""
64
+ expect(v4.major).to eq(0)
65
+ expect(v4.minor).to eq(0)
66
+ expect(v4.patch).to eq(0)
67
+ expect(v4.pre).to be_nil
68
+ expect(v4.build).to eq('hello')
69
+ end
70
+
71
+ it 'provides round-trip fidelity for an empty build parameter' do
72
+ v = Semantic::Version.new('1.2.3')
73
+ v.build = ''
71
74
  expect(Semantic::Version.new(v.to_s).build).to eq(v.build)
72
75
  end
73
76
 
74
- it "provides round-trip fidelity for a nil build parameter" do
75
- v = Semantic::Version.new("1.2.3+build")
77
+ it 'provides round-trip fidelity for a nil build parameter' do
78
+ v = Semantic::Version.new('1.2.3+build')
76
79
  v.build = nil
77
80
  expect(Semantic::Version.new(v.to_s).build).to eq(v.build)
78
81
  end
79
82
  end
80
83
 
81
- context "comparisons" do
84
+ context 'comparisons' do
82
85
  before(:each) do
83
86
  # These three are all semantically equivalent, according to the spec.
84
87
  @v1_5_9_pre_1 = Semantic::Version.new '1.5.9-pre.1'
@@ -87,159 +90,211 @@ describe Semantic::Version do
87
90
 
88
91
  @v1_5_9 = Semantic::Version.new '1.5.9'
89
92
  @v1_6_0 = Semantic::Version.new '1.6.0'
93
+
94
+ @v1_6_0_alpha = Semantic::Version.new '1.6.0-alpha'
95
+ @v1_6_0_alpha_1 = Semantic::Version.new '1.6.0-alpha.1'
96
+ @v1_6_0_alpha_beta = Semantic::Version.new '1.6.0-alpha.beta'
97
+ @v1_6_0_beta = Semantic::Version.new '1.6.0-beta'
98
+ @v1_6_0_beta_2 = Semantic::Version.new '1.6.0-beta.2'
99
+ @v1_6_0_beta_11 = Semantic::Version.new '1.6.0-beta.11'
100
+ @v1_6_0_rc_1 = Semantic::Version.new '1.6.0-rc.1'
101
+
102
+ # expected order:
103
+ # 1.6.0-alpha < 1.6.0-alpha.1 < 1.6.0-alpha.beta < 1.6.0-beta
104
+ # < 1.6.0-beta.2 < 1.6.0-beta.11 < 1.6.0-rc.1 < 1.6.0.
90
105
  end
91
106
 
92
- it "determines sort order" do
93
- # The second parameter here can be a string, so we want to ensure that this kind of comparison works also.
94
- (@v1_5_9_pre_1 <=> @v1_5_9_pre_1.to_s).should == 0
107
+ it 'determines sort order' do
108
+ # The second parameter here can be a string, so we want to ensure that
109
+ # this kind of comparison works also.
110
+ expect((@v1_5_9_pre_1 <=> @v1_5_9_pre_1.to_s)).to eq(0)
95
111
 
96
- (@v1_5_9_pre_1 <=> @v1_5_9_pre_1_build_5127).should == 0
97
- (@v1_5_9_pre_1 <=> @v1_5_9).should == -1
98
- (@v1_5_9_pre_1_build_5127 <=> @v1_5_9).should == -1
112
+ expect((@v1_5_9_pre_1 <=> @v1_5_9_pre_1_build_5127)).to eq(0)
113
+ expect((@v1_5_9_pre_1 <=> @v1_5_9)).to eq(-1)
114
+ expect((@v1_5_9_pre_1_build_5127 <=> @v1_5_9)).to eq(-1)
99
115
 
100
- @v1_5_9_pre_1_build_5127.build.should == 'build.5127'
116
+ expect(@v1_5_9_pre_1_build_5127.build).to eq('build.5127')
101
117
 
102
- (@v1_5_9 <=> @v1_5_9).should == 0
118
+ expect((@v1_5_9 <=> @v1_6_0)).to eq(-1)
119
+ expect((@v1_6_0 <=> @v1_5_9)).to eq(1)
120
+ expect((@v1_6_0 <=> @v1_5_9_pre_1)).to eq(1)
121
+ expect((@v1_5_9_pre_1 <=> @v1_6_0)).to eq(-1)
103
122
 
104
- (@v1_5_9 <=> @v1_6_0).should == -1
105
- (@v1_6_0 <=> @v1_5_9).should == 1
106
- (@v1_6_0 <=> @v1_5_9_pre_1).should == 1
107
- (@v1_5_9_pre_1 <=> @v1_6_0).should == -1
123
+ expect([@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
124
+ .reverse.sort).to \
125
+ eq([@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0])
126
+ end
108
127
 
109
- [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
110
- .reverse
111
- .sort
112
- .should == [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
128
+ it 'determines sort order pre' do
129
+ ary = [@v1_6_0_alpha, @v1_6_0_alpha_1, @v1_6_0_alpha_beta,
130
+ @v1_6_0_beta, @v1_6_0_beta_2, @v1_6_0_beta_11, @v1_6_0_rc_1,
131
+ @v1_6_0]
132
+ expect(ary.shuffle.sort).to eq(ary)
113
133
  end
114
134
 
115
- it "determines whether it is greater than another instance" do
116
- # These should be equal, since "Build metadata SHOULD be ignored when determining version precedence".
135
+ it 'determines whether it is greater than another instance' do
136
+ # These should be equal, since "Build metadata SHOULD be ignored
137
+ # when determining version precedence".
117
138
  # (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
118
- @v1_5_9_pre_1.should_not > @v1_5_9_pre_1_build_5127
119
- @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
139
+ expect(@v1_5_9_pre_1).not_to be > @v1_5_9_pre_1_build_5127
140
+ expect(@v1_5_9_pre_1).not_to be < @v1_5_9_pre_1_build_5127
120
141
 
121
- @v1_6_0.should > @v1_5_9
122
- @v1_5_9.should_not > @v1_6_0
123
- @v1_5_9.should > @v1_5_9_pre_1_build_5127
124
- @v1_5_9.should > @v1_5_9_pre_1
142
+ expect(@v1_6_0).to be > @v1_5_9
143
+ expect(@v1_5_9).not_to be > @v1_6_0
144
+ expect(@v1_5_9).to be > @v1_5_9_pre_1_build_5127
145
+ expect(@v1_5_9).to be > @v1_5_9_pre_1
125
146
  end
126
147
 
127
- it "determines whether it is less than another instance" do
128
- @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
129
- @v1_5_9_pre_1_build_5127.should_not < @v1_5_9_pre_1
130
- @v1_5_9_pre_1.should < @v1_5_9
131
- @v1_5_9_pre_1.should < @v1_6_0
132
- @v1_5_9_pre_1_build_5127.should < @v1_6_0
133
- @v1_5_9.should < @v1_6_0
148
+ it 'determines whether it is less than another instance' do
149
+ expect(@v1_5_9_pre_1).not_to be < @v1_5_9_pre_1_build_5127
150
+ expect(@v1_5_9_pre_1_build_5127).not_to be < @v1_5_9_pre_1
151
+ expect(@v1_5_9_pre_1).to be < @v1_5_9
152
+ expect(@v1_5_9_pre_1).to be < @v1_6_0
153
+ expect(@v1_5_9_pre_1_build_5127).to be < @v1_6_0
154
+ expect(@v1_5_9).to be < @v1_6_0
134
155
  end
135
156
 
136
- it "determines whether it is greater than or equal to another instance" do
137
- @v1_5_9_pre_1.should >= @v1_5_9_pre_1
138
- @v1_5_9_pre_1.should >= @v1_5_9_pre_1_build_5127
139
- @v1_5_9_pre_1_build_5127.should >= @v1_5_9_pre_1
140
- @v1_5_9.should >= @v1_5_9_pre_1
141
- @v1_6_0.should >= @v1_5_9
142
- @v1_5_9_pre_1_build_5127.should_not >= @v1_6_0
157
+ it 'determines whether it is greater than or equal to another instance' do
158
+ expect(@v1_5_9_pre_1).to be >= @v1_5_9_pre_1
159
+ expect(@v1_5_9_pre_1).to be >= @v1_5_9_pre_1_build_5127
160
+ expect(@v1_5_9_pre_1_build_5127).to be >= @v1_5_9_pre_1
161
+ expect(@v1_5_9).to be >= @v1_5_9_pre_1
162
+ expect(@v1_6_0).to be >= @v1_5_9
163
+ expect(@v1_5_9_pre_1_build_5127).not_to be >= @v1_6_0
143
164
  end
144
165
 
145
- it "determines whether it is less than or equal to another instance" do
146
- @v1_5_9_pre_1.should <= @v1_5_9_pre_1_build_5127
147
- @v1_6_0.should_not <= @v1_5_9
148
- @v1_5_9_pre_1_build_5127.should <= @v1_5_9_pre_1_build_5127
149
- @v1_5_9.should_not <= @v1_5_9_pre_1
166
+ it 'determines whether it is less than or equal to another instance' do
167
+ expect(@v1_5_9_pre_1).to be <= @v1_5_9_pre_1_build_5127
168
+ expect(@v1_6_0).not_to be <= @v1_5_9
169
+ expect(@v1_5_9_pre_1_build_5127).to be <= @v1_5_9_pre_1_build_5127
170
+ expect(@v1_5_9).not_to be <= @v1_5_9_pre_1
150
171
  end
151
172
 
152
- it "determines whether it is semantically equal to another instance" do
153
- @v1_5_9_pre_1.should == @v1_5_9_pre_1.dup
154
- @v1_5_9_pre_1_build_5127.should == @v1_5_9_pre_1_build_5127.dup
173
+ it 'determines whether it is semantically equal to another instance' do
174
+ expect(@v1_5_9_pre_1).to eq(@v1_5_9_pre_1.dup)
175
+ expect(@v1_5_9_pre_1_build_5127).to eq(@v1_5_9_pre_1_build_5127.dup)
155
176
 
156
- # "Semantically equal" is the keyword here; these are by definition not "equal" (different build), but should be treated as
177
+ # "Semantically equal" is the keyword here; these are by definition
178
+ # not "equal" (different build), but should be treated as
157
179
  # equal according to the spec.
158
- @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1_build_5127
159
- @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1
180
+ expect(@v1_5_9_pre_1_build_4352).to eq(@v1_5_9_pre_1_build_5127)
181
+ expect(@v1_5_9_pre_1_build_4352).to eq(@v1_5_9_pre_1)
160
182
  end
161
183
 
162
- it "determines whether it satisfies >= style specifications" do
163
- @v1_6_0.satisfies('>=1.6.0').should be true
164
- @v1_6_0.satisfies('<=1.6.0').should be true
165
- @v1_6_0.satisfies('>=1.5.0').should be true
166
- @v1_6_0.satisfies('<=1.5.0').should_not be true
184
+ it 'determines whether it satisfies >= style specifications' do
185
+ expect(@v1_6_0.satisfies('>=1.6.0')).to be true
186
+ expect(@v1_6_0.satisfies('<=1.6.0')).to be true
187
+ expect(@v1_6_0.satisfies('>=1.5.0')).to be true
188
+ expect(@v1_6_0.satisfies('<=1.5.0')).not_to be true
167
189
 
168
190
  # partial / non-semver numbers after comparator are extremely common in
169
191
  # version specifications in the wild
170
192
 
171
- @v1_6_0.satisfies('>1.5').should be true
172
- @v1_6_0.satisfies('<1').should_not be true
193
+ expect(@v1_6_0.satisfies('>1.5')).to be true
194
+ expect(@v1_6_0.satisfies('<1')).not_to be true
173
195
  end
174
196
 
175
- it "determines whether it satisfies * style specifications" do
176
- @v1_6_0.satisfies('1.*').should be true
177
- @v1_6_0.satisfies('1.6.*').should be true
178
- @v1_6_0.satisfies('2.*').should_not be true
179
- @v1_6_0.satisfies('1.5.*').should_not be true
197
+ it 'determines whether it satisfies * style specifications' do
198
+ expect(@v1_6_0.satisfies('1.*')).to be true
199
+ expect(@v1_6_0.satisfies('1.6.*')).to be true
200
+ expect(@v1_6_0.satisfies('2.*')).not_to be true
201
+ expect(@v1_6_0.satisfies('1.5.*')).not_to be true
180
202
  end
181
203
 
182
- it "determines whether it satisfies ~ style specifications" do
183
- @v1_6_0.satisfies('~1.6').should be true
184
- @v1_5_9_pre_1.satisfies('~1.5').should be true
185
- @v1_6_0.satisfies('~1.5').should_not be true
204
+ it 'determines whether it satisfies ~ style specifications' do
205
+ expect(@v1_6_0.satisfies('~1.6')).to be true
206
+ expect(@v1_5_9_pre_1.satisfies('~1.5')).to be true
207
+ expect(@v1_6_0.satisfies('~1.5')).not_to be true
186
208
  end
187
-
188
209
  end
189
210
 
190
- context "type coercions" do
191
- it "converts to a string" do
211
+ context 'type coercions' do
212
+ it 'converts to a string' do
192
213
  @test_versions.each do |v|
193
- Semantic::Version.new(v).to_s.should == v
214
+ expect(Semantic::Version.new(v).to_s).to be == v
194
215
  end
195
216
  end
196
217
 
197
- it "converts to an array" do
198
- Semantic::Version.new('1.0.0').to_a.should == [1, 0, 0, nil, nil]
199
- Semantic::Version.new('6.1.4-pre.5').to_a.should == [6, 1, 4, 'pre.5', nil]
200
- Semantic::Version.new('91.6.0+build.17').to_a.should == [91, 6, 0, nil, 'build.17']
201
- Semantic::Version.new('0.1.5-pre.7+build191').to_a.should == [0, 1, 5, 'pre.7', 'build191']
218
+ it 'converts to an array' do
219
+ expect(Semantic::Version.new('1.0.0').to_a).to \
220
+ eq([1, 0, 0, nil, nil])
221
+ expect(Semantic::Version.new('6.1.4-pre.5').to_a).to \
222
+ eq([6, 1, 4, 'pre.5', nil])
223
+ expect(Semantic::Version.new('91.6.0+build.17').to_a).to \
224
+ eq([91, 6, 0, nil, 'build.17'])
225
+ expect(Semantic::Version.new('0.1.5-pre.7+build191').to_a).to \
226
+ eq([0, 1, 5, 'pre.7', 'build191'])
202
227
  end
203
228
 
204
- it "converts to a hash" do
205
- Semantic::Version.new('1.0.0').to_h.should == { major: 1, minor: 0, patch: 0, pre: nil, build: nil }
206
- Semantic::Version.new('6.1.4-pre.5').to_h.should == { major: 6, minor: 1, patch: 4, pre: 'pre.5', build: nil }
207
- Semantic::Version.new('91.6.0+build.17').to_h.should == { major: 91, minor: 6, patch: 0, pre: nil, build: 'build.17' }
208
- Semantic::Version.new('0.1.5-pre.7+build191').to_h.should == { major: 0, minor: 1, patch: 5, pre: 'pre.7', build: 'build191' }
229
+ it 'converts to a hash' do
230
+ expect(Semantic::Version.new('1.0.0').to_h).to \
231
+ eq(major: 1, minor: 0, patch: 0, pre: nil, build: nil)
232
+ expect(Semantic::Version.new('6.1.4-pre.5').to_h).to \
233
+ eq(major: 6, minor: 1, patch: 4, pre: 'pre.5', build: nil)
234
+ expect(Semantic::Version.new('91.6.0+build.17').to_h).to \
235
+ eq(major: 91, minor: 6, patch: 0, pre: nil, build: 'build.17')
236
+ expect(Semantic::Version.new('0.1.5-pre.7+build191').to_h).to \
237
+ eq(major: 0, minor: 1, patch: 5, pre: 'pre.7', build: 'build191')
209
238
  end
210
239
 
211
- it "aliases conversion methods" do
240
+ it 'aliases conversion methods' do
212
241
  v = Semantic::Version.new('0.0.0')
213
- [:to_hash, :to_array, :to_string].each { |sym| v.should respond_to(sym) }
242
+ [:to_hash, :to_array, :to_string].each do |sym|
243
+ expect(v).to respond_to(sym)
244
+ end
214
245
  end
215
246
  end
216
247
 
248
+ it 'as hash key' do
249
+ hash = {}
250
+ hash[Semantic::Version.new('1.2.3-pre1+build2')] = 'semantic'
251
+ expect(hash[Semantic::Version.new('1.2.3-pre1+build2')]).to eq('semantic')
252
+ end
253
+
217
254
  describe '#major!' do
218
255
  subject { described_class.new('1.2.3-pre1+build2') }
219
256
 
220
257
  context 'changing the major term' do
221
258
  it 'changes the major version and resets the others' do
222
- subject.major!.should == '2.0.0'
259
+ expect(subject.major!).to eq('2.0.0')
223
260
  end
224
261
  end
225
262
  end
226
263
 
227
- describe '#minor' do
264
+ describe '#minor!' do
228
265
  subject { described_class.new('1.2.3-pre1+build2') }
229
266
 
230
267
  context 'changing the minor term' do
231
268
  it 'changes minor term and resets patch, pre and build' do
232
- subject.minor!.should == '1.3.0'
269
+ expect(subject.minor!).to eq('1.3.0')
233
270
  end
234
271
  end
235
272
  end
236
273
 
237
- describe '#patch' do
274
+ describe '#patch!' do
238
275
  subject { described_class.new('1.2.3-pre1+build2') }
239
276
 
240
277
  context 'changing the patch term' do
241
278
  it 'changes the patch term and resets the pre and build' do
242
- subject.patch!.should == '1.2.4'
279
+ expect(subject.patch!).to eq('1.2.4')
280
+ end
281
+ end
282
+ end
283
+
284
+ describe '#increment!' do
285
+ subject { described_class.new('1.2.3-pre1+build2') }
286
+
287
+ context 'changing the minor term' do
288
+ context 'with a string' do
289
+ it 'changes the minor term and resets the path, pre and build' do
290
+ expect(subject.increment!('minor')).to eq('1.3.0')
291
+ end
292
+ end
293
+
294
+ context 'with a symbol' do
295
+ it 'changes the minor term and resets the path, pre and build' do
296
+ expect(subject.increment!(:minor)).to eq('1.3.0')
297
+ end
243
298
  end
244
299
  end
245
300
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lindsey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.1'
19
+ version: '11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '10.1'
26
+ version: '11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.14'
33
+ version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.14'
40
+ version: '3'
41
41
  description: 'Semantic Version utility class for parsing, storing, and comparing versions.
42
42
  See: http://semver.org'
43
43
  email:
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.4.6
77
+ rubygems_version: 2.5.1
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Semantic Version utility class