semantic 1.3.1 → 1.4.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: 8be7b65e62aeac78a5554d3fe5ab776f21531896
4
- data.tar.gz: f07d9b1a21e1b54713a3cb6147e53d0213859b31
3
+ metadata.gz: 8c17513515b4ea394b9402cb707245c00a07590a
4
+ data.tar.gz: 884b649d9f02d0fc203081dcf863cddd61037ed7
5
5
  SHA512:
6
- metadata.gz: 55558e793373d843849a13058ad77db46067046255eb266919f5089c201bbab6c535f53df692707b5781c8b7ec226d077dd2723e5ba6bb588259569075aacdc4
7
- data.tar.gz: b1761377c7f2a5beb1decd3246053906c053e76e465e654a43da102fffe3e00e34dca432ff996c74301fe2472ee968eb804d00950e4f96353bc64e592805969e
6
+ metadata.gz: b81b25d151711e3465f512c241279e1dbebf9442c1b37601a04f5f97d91602168460b47fdbc1fd523c0f4a28d4ed0c1100fb98d66545188a3bc4e61fcdc3e811
7
+ data.tar.gz: b51033a0d6a106fdc7f42bfb3bf0e82a539043467124d209024f0b4a260eb16b96e940dd57084ebd253fc3fdc74fc10d63956e9de6f658bc204bcbcc4963437e
@@ -1,5 +1,5 @@
1
1
  module Semantic
2
- GEM_VERSION = '1.3.1'
2
+ GEM_VERSION = '1.4.0'
3
3
  autoload :Version, 'semantic/version'
4
4
  end
5
5
 
@@ -94,6 +94,22 @@ module Semantic
94
94
  end
95
95
  end
96
96
 
97
+ [:major, :minor, :patch].each do |term|
98
+ define_method("#{term}!") { increment!(term) }
99
+ end
100
+
101
+ def increment!(term)
102
+ new_version = clone
103
+ new_value = send(term) + 1
104
+
105
+ new_version.send("#{term}=", new_value)
106
+ new_version.minor = 0 if term == :major
107
+ new_version.patch = 0 if term == :major || term == :minor
108
+ new_version.build = new_version.pre = nil
109
+
110
+ new_version
111
+ end
112
+
97
113
  private
98
114
 
99
115
  def pad_version_string version_string
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'semantic/core_ext'
3
+
4
+ describe 'Core Extensions' do
5
+ context "String#to_version" do
6
+ before(:each) do
7
+ @test_versions = [
8
+ '1.0.0',
9
+ '12.45.182',
10
+ '0.0.1-pre.1',
11
+ '1.0.1-pre.5+build.123.5',
12
+ '1.1.1+123',
13
+ '0.0.0+hello',
14
+ '1.2.3-1'
15
+ ]
16
+
17
+ @bad_versions = [
18
+ 'a.b.c',
19
+ '1.a.3',
20
+ 'a.3.4',
21
+ '5.2.a',
22
+ 'pre3-1.5.3'
23
+ ]
24
+ end
25
+
26
+ it "extends String with a #to_version method" do
27
+ String.new.should respond_to(:to_version)
28
+ end
29
+
30
+ it "converts the String into a Version object" do
31
+ @test_versions.each do |v|
32
+ expect { v.to_version }.to_not raise_error()
33
+ v.to_version.should be_a(Semantic::Version)
34
+ end
35
+ end
36
+
37
+ it "raises an error on invalid strings" do
38
+ @bad_versions.each do |v|
39
+ expect { v.to_version }.to raise_error()
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ require 'semantic'
9
+
10
+ config.mock_framework = :rspec
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
@@ -0,0 +1,234 @@
1
+ require 'spec_helper'
2
+
3
+ describe Semantic::Version do
4
+ before(:each) do
5
+ @test_versions = [
6
+ '1.0.0',
7
+ '12.45.182',
8
+ '0.0.1-pre.1',
9
+ '1.0.1-pre.5+build.123.5',
10
+ '1.1.1+123',
11
+ '0.0.0+hello',
12
+ '1.2.3-1'
13
+ ]
14
+
15
+ @bad_versions = [
16
+ 'a.b.c',
17
+ '1.a.3',
18
+ 'a.3.4',
19
+ '5.2.a',
20
+ 'pre3-1.5.3',
21
+ "I am not a valid semver\n0.0.0\nbut I still pass"
22
+ ]
23
+ end
24
+
25
+ context "parsing" do
26
+ it "parses valid SemVer versions" do
27
+ @test_versions.each do |v|
28
+ expect { Semantic::Version.new v }.to_not raise_error()
29
+ end
30
+ end
31
+
32
+ it "raises an error on invalid versions" do
33
+ @bad_versions.each do |v|
34
+ expect { Semantic::Version.new v }.to raise_error()
35
+ end
36
+ end
37
+
38
+ it "stores parsed versions in member variables" do
39
+ 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
45
+
46
+ 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
52
+
53
+ 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'
59
+
60
+ 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
+ end
68
+
69
+ context "comparisons" do
70
+ before(:each) do
71
+ # These three are all semantically equivalent, according to the spec.
72
+ @v1_5_9_pre_1 = Semantic::Version.new '1.5.9-pre.1'
73
+ @v1_5_9_pre_1_build_5127 = Semantic::Version.new '1.5.9-pre.1+build.5127'
74
+ @v1_5_9_pre_1_build_4352 = Semantic::Version.new '1.5.9-pre.1+build.4352'
75
+
76
+ @v1_5_9 = Semantic::Version.new '1.5.9'
77
+ @v1_6_0 = Semantic::Version.new '1.6.0'
78
+ end
79
+
80
+ it "determines sort order" do
81
+ # The second parameter here can be a string, so we want to ensure that this kind of comparison works also.
82
+ (@v1_5_9_pre_1 <=> @v1_5_9_pre_1.to_s).should == 0
83
+
84
+ (@v1_5_9_pre_1 <=> @v1_5_9_pre_1_build_5127).should == 0
85
+ (@v1_5_9_pre_1 <=> @v1_5_9).should == -1
86
+ (@v1_5_9_pre_1_build_5127 <=> @v1_5_9).should == -1
87
+
88
+ @v1_5_9_pre_1_build_5127.build.should == 'build.5127'
89
+
90
+ (@v1_5_9 <=> @v1_5_9).should == 0
91
+
92
+ (@v1_5_9 <=> @v1_6_0).should == -1
93
+ (@v1_6_0 <=> @v1_5_9).should == 1
94
+ (@v1_6_0 <=> @v1_5_9_pre_1).should == 1
95
+ (@v1_5_9_pre_1 <=> @v1_6_0).should == -1
96
+
97
+ [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
98
+ .reverse
99
+ .sort
100
+ .should == [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
101
+ end
102
+
103
+ it "determines whether it is greater than another instance" do
104
+ # These should be equal, since "Build metadata SHOULD be ignored when determining version precedence".
105
+ # (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
106
+ @v1_5_9_pre_1.should_not > @v1_5_9_pre_1_build_5127
107
+ @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
108
+
109
+ @v1_6_0.should > @v1_5_9
110
+ @v1_5_9.should_not > @v1_6_0
111
+ @v1_5_9.should > @v1_5_9_pre_1_build_5127
112
+ @v1_5_9.should > @v1_5_9_pre_1
113
+ end
114
+
115
+ it "determines whether it is less than another instance" do
116
+ @v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
117
+ @v1_5_9_pre_1_build_5127.should_not < @v1_5_9_pre_1
118
+ @v1_5_9_pre_1.should < @v1_5_9
119
+ @v1_5_9_pre_1.should < @v1_6_0
120
+ @v1_5_9_pre_1_build_5127.should < @v1_6_0
121
+ @v1_5_9.should < @v1_6_0
122
+ end
123
+
124
+ it "determines whether it is greater than or equal to another instance" do
125
+ @v1_5_9_pre_1.should >= @v1_5_9_pre_1
126
+ @v1_5_9_pre_1.should >= @v1_5_9_pre_1_build_5127
127
+ @v1_5_9_pre_1_build_5127.should >= @v1_5_9_pre_1
128
+ @v1_5_9.should >= @v1_5_9_pre_1
129
+ @v1_6_0.should >= @v1_5_9
130
+ @v1_5_9_pre_1_build_5127.should_not >= @v1_6_0
131
+ end
132
+
133
+ it "determines whether it is less than or equal to another instance" do
134
+ @v1_5_9_pre_1.should <= @v1_5_9_pre_1_build_5127
135
+ @v1_6_0.should_not <= @v1_5_9
136
+ @v1_5_9_pre_1_build_5127.should <= @v1_5_9_pre_1_build_5127
137
+ @v1_5_9.should_not <= @v1_5_9_pre_1
138
+ end
139
+
140
+ it "determines whether it is semantically equal to another instance" do
141
+ @v1_5_9_pre_1.should == @v1_5_9_pre_1.dup
142
+ @v1_5_9_pre_1_build_5127.should == @v1_5_9_pre_1_build_5127.dup
143
+
144
+ # "Semantically equal" is the keyword here; these are by definition not "equal" (different build), but should be treated as
145
+ # equal according to the spec.
146
+ @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1_build_5127
147
+ @v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1
148
+ end
149
+
150
+ it "determines whether it satisfies >= style specifications" do
151
+ @v1_6_0.satisfies('>=1.6.0').should be true
152
+ @v1_6_0.satisfies('<=1.6.0').should be true
153
+ @v1_6_0.satisfies('>=1.5.0').should be true
154
+ @v1_6_0.satisfies('<=1.5.0').should_not be true
155
+
156
+ # partial / non-semver numbers after comparator are extremely common in
157
+ # version specifications in the wild
158
+
159
+ @v1_6_0.satisfies('>1.5').should be true
160
+ @v1_6_0.satisfies('<1').should_not be true
161
+ end
162
+
163
+ it "determines whether it satisfies * style specifications" do
164
+ @v1_6_0.satisfies('1.*').should be true
165
+ @v1_6_0.satisfies('1.6.*').should be true
166
+ @v1_6_0.satisfies('2.*').should_not be true
167
+ @v1_6_0.satisfies('1.5.*').should_not be true
168
+ end
169
+
170
+ it "determines whether it satisfies ~ style specifications" do
171
+ @v1_6_0.satisfies('~1.6').should be true
172
+ @v1_5_9_pre_1.satisfies('~1.5').should be true
173
+ @v1_6_0.satisfies('~1.5').should_not be true
174
+ end
175
+
176
+ end
177
+
178
+ context "type coercions" do
179
+ it "converts to a string" do
180
+ @test_versions.each do |v|
181
+ Semantic::Version.new(v).to_s.should == v
182
+ end
183
+ end
184
+
185
+ it "converts to an array" do
186
+ Semantic::Version.new('1.0.0').to_a.should == [1, 0, 0, nil, nil]
187
+ Semantic::Version.new('6.1.4-pre.5').to_a.should == [6, 1, 4, 'pre.5', nil]
188
+ Semantic::Version.new('91.6.0+build.17').to_a.should == [91, 6, 0, nil, 'build.17']
189
+ Semantic::Version.new('0.1.5-pre.7+build191').to_a.should == [0, 1, 5, 'pre.7', 'build191']
190
+ end
191
+
192
+ it "converts to a hash" do
193
+ Semantic::Version.new('1.0.0').to_h.should == { major: 1, minor: 0, patch: 0, pre: nil, build: nil }
194
+ Semantic::Version.new('6.1.4-pre.5').to_h.should == { major: 6, minor: 1, patch: 4, pre: 'pre.5', build: nil }
195
+ Semantic::Version.new('91.6.0+build.17').to_h.should == { major: 91, minor: 6, patch: 0, pre: nil, build: 'build.17' }
196
+ Semantic::Version.new('0.1.5-pre.7+build191').to_h.should == { major: 0, minor: 1, patch: 5, pre: 'pre.7', build: 'build191' }
197
+ end
198
+
199
+ it "aliases conversion methods" do
200
+ v = Semantic::Version.new('0.0.0')
201
+ [:to_hash, :to_array, :to_string].each { |sym| v.should respond_to(sym) }
202
+ end
203
+ end
204
+
205
+ describe '#major!' do
206
+ subject { described_class.new('1.2.3-pre1+build2') }
207
+
208
+ context 'changing the major term' do
209
+ it 'changes the major version and resets the others' do
210
+ subject.major!.should == '2.0.0'
211
+ end
212
+ end
213
+ end
214
+
215
+ describe '#minor' do
216
+ subject { described_class.new('1.2.3-pre1+build2') }
217
+
218
+ context 'changing the minor term' do
219
+ it 'changes minor term and resets patch, pre and build' do
220
+ subject.minor!.should == '1.3.0'
221
+ end
222
+ end
223
+ end
224
+
225
+ describe '#patch' do
226
+ subject { described_class.new('1.2.3-pre1+build2') }
227
+
228
+ context 'changing the patch term' do
229
+ it 'changes the patch term and resets the pre and build' do
230
+ subject.patch!.should == '1.2.4'
231
+ end
232
+ end
233
+ end
234
+ 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.3.1
4
+ version: 1.4.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: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -51,6 +51,9 @@ files:
51
51
  - lib/semantic.rb
52
52
  - lib/semantic/core_ext.rb
53
53
  - lib/semantic/version.rb
54
+ - spec/core_ext_spec.rb
55
+ - spec/spec_helper.rb
56
+ - spec/version_spec.rb
54
57
  homepage: https://github.com/jlindsey/semantic
55
58
  licenses:
56
59
  - MIT
@@ -75,5 +78,7 @@ rubygems_version: 2.2.2
75
78
  signing_key:
76
79
  specification_version: 4
77
80
  summary: Semantic Version utility class
78
- test_files: []
79
- has_rdoc:
81
+ test_files:
82
+ - spec/core_ext_spec.rb
83
+ - spec/spec_helper.rb
84
+ - spec/version_spec.rb