mixlib-versioning 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +22 -0
  4. data/.travis.yml +24 -0
  5. data/CHANGELOG.md +16 -1
  6. data/Gemfile +3 -4
  7. data/README.md +9 -15
  8. data/Rakefile +15 -3
  9. data/lib/mixlib/versioning.rb +32 -29
  10. data/lib/mixlib/versioning/exceptions.rb +1 -1
  11. data/lib/mixlib/versioning/format.rb +33 -31
  12. data/lib/mixlib/versioning/format/git_describe.rb +5 -7
  13. data/lib/mixlib/versioning/format/opscode_semver.rb +6 -17
  14. data/lib/mixlib/versioning/format/rubygems.rb +6 -8
  15. data/lib/mixlib/versioning/format/semver.rb +9 -11
  16. data/lib/mixlib/versioning/version.rb +2 -2
  17. data/mixlib-versioning.gemspec +20 -14
  18. data/spec/mixlib/versioning/format/git_describe_spec.rb +143 -131
  19. data/spec/mixlib/versioning/format/opscode_semver_spec.rb +106 -81
  20. data/spec/mixlib/versioning/format/rubygems_spec.rb +119 -104
  21. data/spec/mixlib/versioning/format/semver_spec.rb +98 -77
  22. data/spec/mixlib/versioning/format_spec.rb +17 -25
  23. data/spec/mixlib/versioning/versioning_spec.rb +163 -141
  24. data/spec/spec_helper.rb +2 -2
  25. data/spec/support/shared_examples/basic_semver.rb +19 -21
  26. data/spec/support/shared_examples/behaviors/comparable.rb +80 -0
  27. data/spec/support/shared_examples/behaviors/filterable.rb +19 -31
  28. data/spec/support/shared_examples/behaviors/parses_valid_version_strings.rb +4 -7
  29. data/spec/support/shared_examples/behaviors/rejects_invalid_version_strings.rb +3 -6
  30. data/spec/support/shared_examples/behaviors/serializable.rb +5 -7
  31. data/spec/support/shared_examples/behaviors/sortable.rb +7 -9
  32. data/spec/support/shared_examples/semver.rb +81 -69
  33. metadata +51 -26
  34. data/.yardopts +0 -7
  35. data/CONTRIBUTING.md +0 -188
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -38,6 +38,6 @@ RSpec.configure do |config|
38
38
 
39
39
  # specify metadata with symobls only (ie no '=> true' required)
40
40
  config.treat_symbols_as_metadata_keys_with_true_values = true
41
- config.filter_run :focus => true
41
+ config.filter_run focus: true
42
42
  config.run_all_when_everything_filtered = true
43
43
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,27 +16,25 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "Basic SemVer" do
20
-
21
- it_has_behavior "parses valid version strings", {
22
- "1.2.3" => {
23
- :major => 1,
24
- :minor => 2,
25
- :patch => 3,
26
- :prerelease => nil,
27
- :build => nil,
28
- :release? => true,
29
- :prerelease? => false,
30
- :build? => false,
31
- :release_build? => false,
32
- :prerelease_build? => false
33
- }
19
+ shared_examples 'Basic SemVer' do
20
+ it_has_behavior 'parses valid version strings', {
21
+ '1.2.3' => {
22
+ major: 1,
23
+ minor: 2,
24
+ patch: 3,
25
+ prerelease: nil,
26
+ build: nil,
27
+ release?: true,
28
+ prerelease?: false,
29
+ build?: false,
30
+ release_build?: false,
31
+ prerelease_build?: false,
32
+ },
34
33
  }
35
34
 
36
- it_has_behavior "rejects invalid version strings", {
37
- "a.1.1" => "non-numeric MAJOR",
38
- "1.a.1" => "non-numeric MINOR",
39
- "1.1.a" => "non-numeric PATCH"
35
+ it_has_behavior 'rejects invalid version strings', {
36
+ 'a.1.1' => 'non-numeric MAJOR',
37
+ '1.a.1' => 'non-numeric MINOR',
38
+ '1.1.a' => 'non-numeric PATCH',
40
39
  }
41
-
42
40
  end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Krzysztof Wilczynski (<kwilczynski@chef.io>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ shared_examples 'comparable' do |version_matrix|
20
+ describe '#<' do
21
+ version_matrix.each_slice(2) do |a, b|
22
+ it "confirms that #{a} is less-than #{b}" do
23
+ expect(described_class.new(a) < b).to be true
24
+ expect(described_class.new(a) > b).to be false
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#<=' do
30
+ version_matrix.each_slice(2) do |a, b|
31
+ it "confirms that #{a} less-than or equal to #{b}" do
32
+ expect(described_class.new(a) <= b).to be true
33
+ expect(described_class.new(a) <= a).to be true
34
+ expect(described_class.new(a) > b).to be false
35
+ expect(described_class.new(a) == b).to be false
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#==' do
41
+ version_matrix.each do |v|
42
+ it "confirms that #{v} is equal to #{v}" do
43
+ expect(described_class.new(v) == v).to be true
44
+ expect(described_class.new(v) < v).to be false
45
+ expect(described_class.new(v) > v).to be false
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#>' do
51
+ version_matrix.reverse.each_slice(2) do |a, b|
52
+ it "confirms that #{a} is greather-than #{b}" do
53
+ expect(described_class.new(a) > b).to be true
54
+ expect(described_class.new(a) < b).to be false
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#>=' do
60
+ version_matrix.reverse.each_slice(2) do |a, b|
61
+ it "confirms that #{a} greater-than or equal to #{b}" do
62
+ expect(described_class.new(a) >= b).to be true
63
+ expect(described_class.new(a) >= a).to be true
64
+ expect(described_class.new(a) < b).to be false
65
+ expect(described_class.new(a) == b).to be false
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#between?' do
71
+ let(:versions) { version_matrix.map { |v| described_class.new(v) }.sort }
72
+
73
+ it 'comfirms that a version is between the oldest and latest release' do
74
+ min, max = versions.minmax.map(&:to_s)
75
+ middle = versions[versions.size / 2].to_s
76
+ expect(described_class.new(middle).between?(min, max)).to be true
77
+ expect(described_class.new(middle).between?(max, min)).to be false
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,51 +16,39 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "filterable" do
20
-
19
+ shared_examples 'filterable' do
21
20
  let(:unsorted_versions) do
22
- unsorted_version_strings.map{ |v| described_class.new(v) }
21
+ unsorted_version_strings.map { |v| described_class.new(v) }
23
22
  end
24
23
 
25
24
  # this should/will be overriden by calling spec
26
- let(:release_versions){[]}
27
- let(:prerelease_versions){[]}
28
- let(:build_versions){[]}
29
- let(:release_build_versions){[]}
30
- let(:prerelease_build_versions){[]}
31
-
32
- it "filters by release versions only" do
33
- unsorted_versions.select(&:release?).should eq(release_versions.map{|v|
34
- described_class.new(v)
35
- })
25
+ let(:release_versions) { [] }
26
+ let(:prerelease_versions) { [] }
27
+ let(:build_versions) { [] }
28
+ let(:release_build_versions) { [] }
29
+ let(:prerelease_build_versions) { [] }
30
+
31
+ it 'filters by release versions only' do
32
+ unsorted_versions.select(&:release?).should eq(release_versions.map { |v| described_class.new(v) })
36
33
  end # it
37
34
 
38
- it "filters by pre-release versions only" do
35
+ it 'filters by pre-release versions only' do
39
36
  filtered = unsorted_versions.select(&:prerelease?)
40
- filtered.should eq(prerelease_versions.map{|v|
41
- described_class.new(v)
42
- })
37
+ filtered.should eq(prerelease_versions.map { |v| described_class.new(v) })
43
38
  end # it
44
39
 
45
- it "filters by build versions only" do
40
+ it 'filters by build versions only' do
46
41
  filtered = unsorted_versions.select(&:build?)
47
- filtered.should eq(build_versions.map{|v|
48
- described_class.new(v)
49
- })
42
+ filtered.should eq(build_versions.map { |v| described_class.new(v) })
50
43
  end # it
51
44
 
52
- it "filters by release build versions only" do
45
+ it 'filters by release build versions only' do
53
46
  filtered = unsorted_versions.select(&:release_build?)
54
- filtered.should eq(release_build_versions.map{|v|
55
- described_class.new(v)
56
- })
47
+ filtered.should eq(release_build_versions.map { |v| described_class.new(v) })
57
48
  end # it
58
49
 
59
- it "filters by pre-release build versions only" do
50
+ it 'filters by pre-release build versions only' do
60
51
  filtered = unsorted_versions.select(&:prerelease_build?)
61
- filtered.should eq(prerelease_build_versions.map{|v|
62
- described_class.new(v)
63
- })
52
+ filtered.should eq(prerelease_build_versions.map { |v| described_class.new(v) })
64
53
  end # it
65
-
66
54
  end # shared_examples
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,17 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "parses valid version strings" do |valid_examples|
20
-
19
+ shared_examples 'parses valid version strings' do |valid_examples|
21
20
  valid_examples.each do |version, options|
22
-
23
21
  context version do
24
- let(:version_string){ version }
22
+ let(:version_string) { version }
25
23
 
26
24
  options.each_pair do |name, value|
27
- its(name){ should eq value}
25
+ its(name) { should eq value }
28
26
  end
29
-
30
27
  end # context
31
28
  end # valid_examples
32
29
  end # shared_examples
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,17 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "rejects invalid version strings" do |invalid_examples|
20
-
19
+ shared_examples 'rejects invalid version strings' do |invalid_examples|
21
20
  invalid_examples.each_pair do |version, reason|
22
-
23
21
  context version do
24
- let(:version_string){ version }
22
+ let(:version_string) { version }
25
23
 
26
24
  it "fails because: #{reason}" do
27
25
  expect { subject }.to raise_error(Mixlib::Versioning::ParseError)
28
26
  end
29
-
30
27
  end # context
31
28
  end # invalid_examples
32
29
  end # shared_examples
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,9 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "serializable" do |version_strings|
20
-
21
- describe "#to_s" do
19
+ shared_examples 'serializable' do |version_strings|
20
+ describe '#to_s' do
22
21
  version_strings.each do |v|
23
22
  it "reconstructs the initial input for #{v}" do
24
23
  described_class.new(v).to_s.should == v
@@ -26,7 +25,7 @@ shared_examples "serializable" do |version_strings|
26
25
  end # version_strings
27
26
  end # describe
28
27
 
29
- describe "#to_semver_string" do
28
+ describe '#to_semver_string' do
30
29
  version_strings.each do |v|
31
30
  it "generates a semver version string for #{v}" do
32
31
  subject = described_class.new(v)
@@ -37,7 +36,7 @@ shared_examples "serializable" do |version_strings|
37
36
  end # version_strings
38
37
  end # describe
39
38
 
40
- describe "#to_rubygems_string" do
39
+ describe '#to_rubygems_string' do
41
40
  version_strings.each do |v|
42
41
  it "generates a rubygems version string for #{v}" do
43
42
  subject = described_class.new(v)
@@ -47,5 +46,4 @@ shared_examples "serializable" do |version_strings|
47
46
  end # it
48
47
  end # version_strings
49
48
  end # describe
50
-
51
49
  end # shared_examples
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -16,30 +16,28 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- shared_examples "sortable" do
20
-
19
+ shared_examples 'sortable' do
21
20
  let(:unsorted_versions) do
22
- unsorted_version_strings.map{ |v| described_class.new(v) }
21
+ unsorted_version_strings.map { |v| described_class.new(v) }
23
22
  end
24
23
 
25
24
  let(:sorted_versions) do
26
- sorted_version_strings.map{ |v| described_class.new(v) }
25
+ sorted_version_strings.map { |v| described_class.new(v) }
27
26
  end
28
27
 
29
28
  it 'responds to <=>' do
30
29
  described_class.should respond_to(:<=>)
31
30
  end
32
31
 
33
- it "sorts all properly" do
32
+ it 'sorts all properly' do
34
33
  unsorted_versions.sort.should eq sorted_versions
35
34
  end
36
35
 
37
- it "finds the min" do
36
+ it 'finds the min' do
38
37
  unsorted_versions.min.should eq described_class.new(min)
39
38
  end
40
39
 
41
- it "finds the max" do
40
+ it 'finds the max' do
42
41
  unsorted_versions.max.should eq described_class.new(max)
43
42
  end
44
-
45
43
  end # shared_examples
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
3
  # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
@@ -19,87 +19,99 @@
19
19
  require 'mixlib/versioning'
20
20
 
21
21
  shared_examples Mixlib::Versioning::Format::SemVer do
22
+ it_should_behave_like 'Basic SemVer'
22
23
 
23
- it_should_behave_like "Basic SemVer"
24
-
25
- it_has_behavior "parses valid version strings", {
26
- "1.0.0-alpha.1" => {
27
- :major => 1,
28
- :minor => 0,
29
- :patch => 0,
30
- :prerelease => "alpha.1",
31
- :build => nil,
32
- :release? => false,
33
- :prerelease? => true,
34
- :build? => false,
35
- :release_build? => false,
36
- :prerelease_build? => false
24
+ it_has_behavior 'parses valid version strings', {
25
+ '1.0.0-alpha.1' => {
26
+ major: 1,
27
+ minor: 0,
28
+ patch: 0,
29
+ prerelease: 'alpha.1',
30
+ build: nil,
31
+ release?: false,
32
+ prerelease?: true,
33
+ build?: false,
34
+ release_build?: false,
35
+ prerelease_build?: false,
36
+ },
37
+ '1.0.0+20130308110833' => {
38
+ major: 1,
39
+ minor: 0,
40
+ patch: 0,
41
+ prerelease: nil,
42
+ build: '20130308110833',
43
+ release?: false,
44
+ prerelease?: false,
45
+ build?: true,
46
+ release_build?: true,
47
+ prerelease_build?: false,
37
48
  },
38
- "1.0.0+20130308110833" => {
39
- :major => 1,
40
- :minor => 0,
41
- :patch => 0,
42
- :prerelease => nil,
43
- :build => "20130308110833",
44
- :release? => false,
45
- :prerelease? => false,
46
- :build? => true,
47
- :release_build? => true,
48
- :prerelease_build? => false
49
+ '1.0.0-beta.3+20130308110833' => {
50
+ major: 1,
51
+ minor: 0,
52
+ patch: 0,
53
+ prerelease: 'beta.3',
54
+ build: '20130308110833',
55
+ release?: false,
56
+ prerelease?: false,
57
+ build?: true,
58
+ release_build?: false,
59
+ prerelease_build?: true,
49
60
  },
50
- "1.0.0-beta.3+20130308110833" => {
51
- :major => 1,
52
- :minor => 0,
53
- :patch => 0,
54
- :prerelease => "beta.3",
55
- :build => "20130308110833",
56
- :release? => false,
57
- :prerelease? => false,
58
- :build? => true,
59
- :release_build? => false,
60
- :prerelease_build? => true
61
- }
62
61
  }
63
62
 
64
- it_has_behavior "rejects invalid version strings", {
65
- "8.8.8.8" => "too many segments: MAJOR.MINOR.PATCH.EXTRA"
63
+ it_has_behavior 'rejects invalid version strings', {
64
+ '8.8.8.8' => 'too many segments: MAJOR.MINOR.PATCH.EXTRA',
65
+ '01.1.1' => 'leading zero invalid',
66
+ '1.01.1' => 'leading zero invalid',
67
+ '1.1.01' => 'leading zero invalid',
68
+ '1.0.0-' => 'empty prerelease identifier',
69
+ '1.0.0-alpha..' => 'empty prerelease identifier',
70
+ '1.0.0-01.02.03' => 'leading zero invalid',
71
+ '1.0.0-alpha.01' => 'leading zero invalid',
72
+ '6.3.1+' => 'empty build identifier',
73
+ '6.4.8-alpha.1.2.3+build.' => 'empty build identifier',
74
+ '4.0.000000000002-alpha.1' => 'leading zero invalid',
75
+ '007.2.3-rc.1+build.16' => 'leading zero invalid',
76
+ '12.0005.1-alpha.12' => 'leading zero invalid',
77
+ '12.2.10-beta.00000017' => 'leading zero invalid',
66
78
  }
67
79
 
68
- describe "build qualification" do
69
- context "release version" do
70
- let(:version_string){"1.0.0"}
71
- its(:release?){ should be_true }
72
- its(:prerelease?){ should be_false }
73
- its(:build?){ should be_false }
74
- its(:release_build?){ should be_false }
75
- its(:prerelease_build?){ should be_false }
80
+ describe 'build qualification' do
81
+ context 'release version' do
82
+ let(:version_string) { '1.0.0' }
83
+ its(:release?) { should be_true }
84
+ its(:prerelease?) { should be_false }
85
+ its(:build?) { should be_false }
86
+ its(:release_build?) { should be_false }
87
+ its(:prerelease_build?) { should be_false }
76
88
  end
77
89
 
78
- context "pre-release version" do
79
- let(:version_string){"1.0.0-alpha.1"}
80
- its(:release?){ should be_false }
81
- its(:prerelease?){ should be_true }
82
- its(:build?){ should be_false }
83
- its(:release_build?){ should be_false }
84
- its(:prerelease_build?){ should be_false }
90
+ context 'pre-release version' do
91
+ let(:version_string) { '1.0.0-alpha.1' }
92
+ its(:release?) { should be_false }
93
+ its(:prerelease?) { should be_true }
94
+ its(:build?) { should be_false }
95
+ its(:release_build?) { should be_false }
96
+ its(:prerelease_build?) { should be_false }
85
97
  end
86
98
 
87
- context "pre-release build version" do
88
- let(:version_string){"1.0.0-alpha.1+20130308110833"}
89
- its(:release?){ should be_false }
90
- its(:prerelease?){ should be_false }
91
- its(:build?){ should be_true }
92
- its(:release_build?){ should be_false }
93
- its(:prerelease_build?){ should be_true }
99
+ context 'pre-release build version' do
100
+ let(:version_string) { '1.0.0-alpha.1+20130308110833' }
101
+ its(:release?) { should be_false }
102
+ its(:prerelease?) { should be_false }
103
+ its(:build?) { should be_true }
104
+ its(:release_build?) { should be_false }
105
+ its(:prerelease_build?) { should be_true }
94
106
  end
95
107
 
96
- context "release build version" do
97
- let(:version_string){"1.0.0+20130308110833"}
98
- its(:release?){ should be_false }
99
- its(:prerelease?){ should be_false }
100
- its(:build?){ should be_true }
101
- its(:release_build?){ should be_true }
102
- its(:prerelease_build?){ should be_false }
108
+ context 'release build version' do
109
+ let(:version_string) { '1.0.0+20130308110833' }
110
+ its(:release?) { should be_false }
111
+ its(:prerelease?) { should be_false }
112
+ its(:build?) { should be_true }
113
+ its(:release_build?) { should be_true }
114
+ its(:prerelease_build?) { should be_false }
103
115
  end
104
116
  end
105
117
  end