mixlib-versioning 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +188 -0
- data/Gemfile +9 -0
- data/LICENSE +201 -0
- data/README.md +364 -0
- data/Rakefile +6 -0
- data/lib/mixlib/versioning.rb +194 -0
- data/lib/mixlib/versioning/exceptions.rb +28 -0
- data/lib/mixlib/versioning/format.rb +351 -0
- data/lib/mixlib/versioning/format/git_describe.rb +71 -0
- data/lib/mixlib/versioning/format/opscode_semver.rb +91 -0
- data/lib/mixlib/versioning/format/rubygems.rb +66 -0
- data/lib/mixlib/versioning/format/semver.rb +66 -0
- data/lib/mixlib/versioning/version.rb +23 -0
- data/mixlib-versioning.gemspec +22 -0
- data/spec/mixlib/versioning/format/git_describe_spec.rb +178 -0
- data/spec/mixlib/versioning/format/opscode_semver_spec.rb +113 -0
- data/spec/mixlib/versioning/format/rubygems_spec.rb +142 -0
- data/spec/mixlib/versioning/format/semver_spec.rb +107 -0
- data/spec/mixlib/versioning/format_spec.rb +69 -0
- data/spec/mixlib/versioning/versioning_spec.rb +259 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/shared_examples/basic_semver.rb +42 -0
- data/spec/support/shared_examples/behaviors/filterable.rb +66 -0
- data/spec/support/shared_examples/behaviors/parses_valid_version_strings.rb +32 -0
- data/spec/support/shared_examples/behaviors/rejects_invalid_version_strings.rb +32 -0
- data/spec/support/shared_examples/behaviors/serializable.rb +51 -0
- data/spec/support/shared_examples/behaviors/sortable.rb +45 -0
- data/spec/support/shared_examples/semver.rb +105 -0
- metadata +127 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Mixlib::Versioning::Format::OpscodeSemVer do
|
22
|
+
|
23
|
+
subject{ described_class.new(version_string) }
|
24
|
+
|
25
|
+
it_should_behave_like Mixlib::Versioning::Format::SemVer
|
26
|
+
|
27
|
+
it_has_behavior "rejects invalid version strings", {
|
28
|
+
"1.0.0-poop.0" => "non-valid pre-release type",
|
29
|
+
"1.0.0+2010AA08010101" => "a malformed timestamp",
|
30
|
+
"1.0.0+cvs.33.e0f985a" => "a malformed git describe: no git string",
|
31
|
+
"1.0.0+git.AA.e0f985a" => "a malformed git describe: non-numeric COMMITS_SINCE",
|
32
|
+
"1.0.0+git.33.z0f985a" => "a malformed git describe: invalid SHA1"
|
33
|
+
}
|
34
|
+
|
35
|
+
it_has_behavior "serializable", [
|
36
|
+
"1.0.0",
|
37
|
+
"1.0.0-alpha.1",
|
38
|
+
"1.0.0-alpha.1+20130308110833",
|
39
|
+
"1.0.0+20130308110833.git.2.94a1dde"
|
40
|
+
]
|
41
|
+
|
42
|
+
it_has_behavior "sortable" do
|
43
|
+
let(:unsorted_version_strings){%w{
|
44
|
+
1.0.0-beta.2
|
45
|
+
1.0.0-alpha
|
46
|
+
1.0.0-rc.1+20130309074433
|
47
|
+
1.0.0
|
48
|
+
1.0.0-beta.11
|
49
|
+
1.0.0+20121009074433
|
50
|
+
1.0.0-rc.1
|
51
|
+
1.0.0-alpha.1
|
52
|
+
1.3.7+20131009104433.git.2.94a1dde
|
53
|
+
1.3.7+20131009104433
|
54
|
+
1.3.7+20131009074433
|
55
|
+
}}
|
56
|
+
let(:sorted_version_strings){%w{
|
57
|
+
1.0.0-alpha
|
58
|
+
1.0.0-alpha.1
|
59
|
+
1.0.0-beta.2
|
60
|
+
1.0.0-beta.11
|
61
|
+
1.0.0-rc.1
|
62
|
+
1.0.0-rc.1+20130309074433
|
63
|
+
1.0.0
|
64
|
+
1.0.0+20121009074433
|
65
|
+
1.3.7+20131009074433
|
66
|
+
1.3.7+20131009104433
|
67
|
+
1.3.7+20131009104433.git.2.94a1dde
|
68
|
+
}}
|
69
|
+
let(:min){ "1.0.0-alpha" }
|
70
|
+
let(:max){ "1.3.7+20131009104433.git.2.94a1dde" }
|
71
|
+
end # it_has_behavior
|
72
|
+
|
73
|
+
it_has_behavior "filterable" do
|
74
|
+
let(:unsorted_version_strings){%w{
|
75
|
+
1.0.0-beta.2
|
76
|
+
1.0.0-alpha
|
77
|
+
1.0.0-rc.1+20130309074433
|
78
|
+
1.0.0
|
79
|
+
1.0.0-beta.11
|
80
|
+
1.0.0+20121009074433
|
81
|
+
1.0.0-rc.1
|
82
|
+
1.0.0-alpha.1
|
83
|
+
1.3.7+20131009104433.git.2.94a1dde
|
84
|
+
1.3.7+20131009104433
|
85
|
+
1.3.7+20131009074433
|
86
|
+
}}
|
87
|
+
let(:release_versions){%w{ 1.0.0 }}
|
88
|
+
let(:prerelease_versions){%w{
|
89
|
+
1.0.0-beta.2
|
90
|
+
1.0.0-alpha
|
91
|
+
1.0.0-beta.11
|
92
|
+
1.0.0-rc.1
|
93
|
+
1.0.0-alpha.1
|
94
|
+
}}
|
95
|
+
let(:build_versions){%w{
|
96
|
+
1.0.0-rc.1+20130309074433
|
97
|
+
1.0.0+20121009074433
|
98
|
+
1.3.7+20131009104433.git.2.94a1dde
|
99
|
+
1.3.7+20131009104433
|
100
|
+
1.3.7+20131009074433
|
101
|
+
}}
|
102
|
+
let(:release_build_versions){%w{
|
103
|
+
1.0.0+20121009074433
|
104
|
+
1.3.7+20131009104433.git.2.94a1dde
|
105
|
+
1.3.7+20131009104433
|
106
|
+
1.3.7+20131009074433
|
107
|
+
}}
|
108
|
+
let(:prerelease_build_versions){%w{
|
109
|
+
1.0.0-rc.1+20130309074433
|
110
|
+
}}
|
111
|
+
end # it_has_behavior
|
112
|
+
|
113
|
+
end # describe
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Mixlib::Versioning::Format::Rubygems do
|
22
|
+
|
23
|
+
subject{ described_class.new(version_string) }
|
24
|
+
|
25
|
+
it_should_behave_like "Basic SemVer"
|
26
|
+
|
27
|
+
it_has_behavior "parses valid version strings", {
|
28
|
+
"10.1.1" => {
|
29
|
+
:major => 10,
|
30
|
+
:minor => 1,
|
31
|
+
:patch => 1,
|
32
|
+
:prerelease => nil,
|
33
|
+
:build => nil,
|
34
|
+
:release? => true,
|
35
|
+
:prerelease? => false,
|
36
|
+
:build? => false,
|
37
|
+
:release_build? => false,
|
38
|
+
:prerelease_build? => false,
|
39
|
+
:iteration => 0
|
40
|
+
},
|
41
|
+
"10.1.1.alpha.1" => {
|
42
|
+
:major => 10,
|
43
|
+
:minor => 1,
|
44
|
+
:patch => 1,
|
45
|
+
:prerelease => "alpha.1",
|
46
|
+
:build => nil,
|
47
|
+
:release? => false,
|
48
|
+
:prerelease? => true,
|
49
|
+
:build? => false,
|
50
|
+
:release_build? => false,
|
51
|
+
:prerelease_build? => false,
|
52
|
+
:iteration => 0
|
53
|
+
},
|
54
|
+
"11.0.8.rc.3" => {
|
55
|
+
:major => 11,
|
56
|
+
:minor => 0,
|
57
|
+
:patch => 8,
|
58
|
+
:prerelease => "rc.3",
|
59
|
+
:build => nil,
|
60
|
+
:release? => false,
|
61
|
+
:prerelease? => true,
|
62
|
+
:build? => false,
|
63
|
+
:release_build? => false,
|
64
|
+
:prerelease_build? => false,
|
65
|
+
:iteration => 0
|
66
|
+
},
|
67
|
+
"11.0.8-33" => {
|
68
|
+
:major => 11,
|
69
|
+
:minor => 0,
|
70
|
+
:patch => 8,
|
71
|
+
:prerelease => nil,
|
72
|
+
:build => nil,
|
73
|
+
:release? => true,
|
74
|
+
:prerelease? => false,
|
75
|
+
:build? => false,
|
76
|
+
:release_build? => false,
|
77
|
+
:prerelease_build? => false,
|
78
|
+
:iteration => 33
|
79
|
+
},
|
80
|
+
"11.0.8.rc.3-1" => {
|
81
|
+
:major => 11,
|
82
|
+
:minor => 0,
|
83
|
+
:patch => 8,
|
84
|
+
:prerelease => "rc.3",
|
85
|
+
:build => nil,
|
86
|
+
:release? => false,
|
87
|
+
:prerelease? => true,
|
88
|
+
:build? => false,
|
89
|
+
:release_build? => false,
|
90
|
+
:prerelease_build? => false,
|
91
|
+
:iteration => 1
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
it_has_behavior "rejects invalid version strings", {
|
96
|
+
"1.1.1-rutro" => "dash for pre-release delimeter"
|
97
|
+
}
|
98
|
+
|
99
|
+
it_has_behavior "serializable", [
|
100
|
+
"1.0.0",
|
101
|
+
"1.0.0.alpha.1",
|
102
|
+
"1.0.0.beta"
|
103
|
+
]
|
104
|
+
|
105
|
+
it_has_behavior "sortable" do
|
106
|
+
let(:unsorted_version_strings){%w{
|
107
|
+
1.0.0.beta.2
|
108
|
+
1.3.7.alpha.0
|
109
|
+
1.0.0.alpha
|
110
|
+
1.0.0.rc.1
|
111
|
+
1.0.0
|
112
|
+
}}
|
113
|
+
let(:sorted_version_strings){%w{
|
114
|
+
1.0.0.alpha
|
115
|
+
1.0.0.beta.2
|
116
|
+
1.0.0.rc.1
|
117
|
+
1.0.0
|
118
|
+
1.3.7.alpha.0
|
119
|
+
}}
|
120
|
+
let(:min){ "1.0.0.alpha" }
|
121
|
+
let(:max){ "1.3.7.alpha.0" }
|
122
|
+
end
|
123
|
+
|
124
|
+
# The +Rubygems+ format only produces release and prerelease versions.
|
125
|
+
it_has_behavior "filterable" do
|
126
|
+
let(:unsorted_version_strings){%w{
|
127
|
+
1.0.0.beta.2
|
128
|
+
1.3.7.alpha.0
|
129
|
+
1.0.0.alpha
|
130
|
+
1.0.0.rc.1
|
131
|
+
1.0.0
|
132
|
+
}}
|
133
|
+
let(:release_versions){%w{ 1.0.0 }}
|
134
|
+
let(:prerelease_versions){%w{
|
135
|
+
1.0.0.beta.2
|
136
|
+
1.3.7.alpha.0
|
137
|
+
1.0.0.alpha
|
138
|
+
1.0.0.rc.1
|
139
|
+
}}
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Mixlib::Versioning::Format::SemVer do
|
22
|
+
|
23
|
+
subject{ described_class.new(version_string) }
|
24
|
+
|
25
|
+
it_should_behave_like Mixlib::Versioning::Format::SemVer
|
26
|
+
|
27
|
+
it_has_behavior "serializable", [
|
28
|
+
"1.0.0",
|
29
|
+
"1.0.0-alpha.1",
|
30
|
+
"1.0.0-alpha.1+some.build.version",
|
31
|
+
"1.0.0+build.build.build"
|
32
|
+
]
|
33
|
+
|
34
|
+
it_has_behavior "sortable" do
|
35
|
+
let(:unsorted_version_strings){%w{
|
36
|
+
1.0.0-beta.2
|
37
|
+
1.0.0-alpha
|
38
|
+
1.0.0-rc.1+build.1
|
39
|
+
1.0.0
|
40
|
+
1.0.0-beta.11
|
41
|
+
1.0.0+0.3.7
|
42
|
+
1.0.0-rc.1
|
43
|
+
1.0.0-alpha.1
|
44
|
+
1.3.7+build.2.b8f12d7
|
45
|
+
1.3.7+build.11.e0f985a
|
46
|
+
1.3.7+build
|
47
|
+
}}
|
48
|
+
let(:sorted_version_strings){%w{
|
49
|
+
1.0.0-alpha
|
50
|
+
1.0.0-alpha.1
|
51
|
+
1.0.0-beta.2
|
52
|
+
1.0.0-beta.11
|
53
|
+
1.0.0-rc.1
|
54
|
+
1.0.0-rc.1+build.1
|
55
|
+
1.0.0
|
56
|
+
1.0.0+0.3.7
|
57
|
+
1.3.7+build
|
58
|
+
1.3.7+build.2.b8f12d7
|
59
|
+
1.3.7+build.11.e0f985a
|
60
|
+
}}
|
61
|
+
let(:min){ "1.0.0-alpha" }
|
62
|
+
let(:max){ "1.3.7+build.11.e0f985a" }
|
63
|
+
end # it_has_behavior
|
64
|
+
|
65
|
+
it_has_behavior "filterable" do
|
66
|
+
let(:unsorted_version_strings){%w{
|
67
|
+
1.0.0-beta.2
|
68
|
+
1.0.0-alpha
|
69
|
+
1.0.0-rc.1+build.1
|
70
|
+
1.0.0
|
71
|
+
1.0.0-beta.11
|
72
|
+
1.0.0+0.3.7
|
73
|
+
1.0.0-rc.1
|
74
|
+
1.0.0-alpha.1
|
75
|
+
1.3.7+build.2.b8f12d7
|
76
|
+
1.3.7+build.11.e0f985a
|
77
|
+
1.3.7+build
|
78
|
+
}}
|
79
|
+
let(:release_versions){%w{
|
80
|
+
1.0.0
|
81
|
+
}}
|
82
|
+
let(:prerelease_versions){%w{
|
83
|
+
1.0.0-beta.2
|
84
|
+
1.0.0-alpha
|
85
|
+
1.0.0-beta.11
|
86
|
+
1.0.0-rc.1
|
87
|
+
1.0.0-alpha.1
|
88
|
+
}}
|
89
|
+
let(:build_versions){%w{
|
90
|
+
1.0.0-rc.1+build.1
|
91
|
+
1.0.0+0.3.7
|
92
|
+
1.3.7+build.2.b8f12d7
|
93
|
+
1.3.7+build.11.e0f985a
|
94
|
+
1.3.7+build
|
95
|
+
}}
|
96
|
+
let(:release_build_versions){%w{
|
97
|
+
1.0.0+0.3.7
|
98
|
+
1.3.7+build.2.b8f12d7
|
99
|
+
1.3.7+build.11.e0f985a
|
100
|
+
1.3.7+build
|
101
|
+
}}
|
102
|
+
let(:prerelease_build_versions){%w{
|
103
|
+
1.0.0-rc.1+build.1
|
104
|
+
}}
|
105
|
+
end # it_has_behavior
|
106
|
+
|
107
|
+
end # describe
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Mixlib::Versioning::Format do
|
22
|
+
|
23
|
+
describe "#initialize" do
|
24
|
+
subject{ described_class.new(version_string) }
|
25
|
+
let(:version_string) { "11.0.0" }
|
26
|
+
|
27
|
+
it "descendants must override #parse" do
|
28
|
+
expect { subject }.to raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".for" do
|
33
|
+
|
34
|
+
subject{ described_class }
|
35
|
+
|
36
|
+
[
|
37
|
+
:rubygems,
|
38
|
+
"rubygems",
|
39
|
+
Mixlib::Versioning::Format::Rubygems
|
40
|
+
].each do |format_type|
|
41
|
+
|
42
|
+
context "format_type is a: #{format_type.class}" do
|
43
|
+
let(:format_type){ format_type }
|
44
|
+
it "returns the correct format class" do
|
45
|
+
subject.for(format_type).should eq Mixlib::Versioning::Format::Rubygems
|
46
|
+
end # it
|
47
|
+
end # context
|
48
|
+
|
49
|
+
end # each
|
50
|
+
|
51
|
+
describe "unknown format_type" do
|
52
|
+
[
|
53
|
+
:poop,
|
54
|
+
"poop",
|
55
|
+
Mixlib::Versioning
|
56
|
+
].each do |invalid_format_type|
|
57
|
+
|
58
|
+
context "format_type is a: #{invalid_format_type.class}" do
|
59
|
+
it "raises a Mixlib::Versioning::UnknownFormatError" do
|
60
|
+
expect { subject.for(invalid_format_type) }.to raise_error(Mixlib::Versioning::UnknownFormatError)
|
61
|
+
end # it
|
62
|
+
end # context
|
63
|
+
|
64
|
+
end # each
|
65
|
+
end # describe
|
66
|
+
|
67
|
+
end # describe ".for"
|
68
|
+
|
69
|
+
end # describe Mixlib::Versioning::Format
|
@@ -0,0 +1,259 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Mixlib::Versioning do
|
22
|
+
|
23
|
+
subject{ described_class }
|
24
|
+
|
25
|
+
let(:version_string){ "11.0.0" }
|
26
|
+
|
27
|
+
describe ".parse" do
|
28
|
+
|
29
|
+
describe "parsing when format type is specified" do
|
30
|
+
{
|
31
|
+
"11.0.8" => {
|
32
|
+
:format_type => :semver,
|
33
|
+
:expected_format => Mixlib::Versioning::Format::SemVer
|
34
|
+
},
|
35
|
+
"11.1.1" => {
|
36
|
+
:format_type => :rubygems,
|
37
|
+
:expected_format => Mixlib::Versioning::Format::Rubygems
|
38
|
+
},
|
39
|
+
"11.1.1.alpha.1" => {
|
40
|
+
:format_type => :rubygems,
|
41
|
+
:expected_format => Mixlib::Versioning::Format::Rubygems
|
42
|
+
},
|
43
|
+
"11.1.1-alpha.1" => {
|
44
|
+
:format_type => :opscode_semver,
|
45
|
+
:expected_format => Mixlib::Versioning::Format::OpscodeSemVer
|
46
|
+
},
|
47
|
+
"11.1.1-rc.2" => {
|
48
|
+
:format_type => :opscode_semver,
|
49
|
+
:expected_format => Mixlib::Versioning::Format::SemVer
|
50
|
+
}
|
51
|
+
}.each_pair do |version_string, options|
|
52
|
+
|
53
|
+
context "#{version_string} as #{options[:expected_format]}" do
|
54
|
+
let(:version_string){ version_string }
|
55
|
+
let(:expected_format){ options[:expected_format] }
|
56
|
+
|
57
|
+
[
|
58
|
+
options[:format_type],
|
59
|
+
options[:format_type].to_s,
|
60
|
+
options[:expected_format]
|
61
|
+
].each do |format_type|
|
62
|
+
|
63
|
+
context "format type as a: #{format_type.class}" do
|
64
|
+
it "parses version string as: #{options[:expected_format]}" do
|
65
|
+
result = subject.parse(version_string, format_type)
|
66
|
+
result.should be_a(expected_format)
|
67
|
+
end # it
|
68
|
+
end # context
|
69
|
+
|
70
|
+
end # each
|
71
|
+
end # context
|
72
|
+
end # each_pair
|
73
|
+
|
74
|
+
|
75
|
+
describe "invalid format type specified" do
|
76
|
+
[
|
77
|
+
:poop,
|
78
|
+
"poop",
|
79
|
+
Mixlib::Versioning
|
80
|
+
].each do |invalid_format_type|
|
81
|
+
|
82
|
+
context "invalid format as a: #{invalid_format_type.class}" do
|
83
|
+
it "raises a Mixlib::Versioning::UnknownFormatError" do
|
84
|
+
expect { subject.parse(version_string, invalid_format_type) }.to raise_error(Mixlib::Versioning::UnknownFormatError)
|
85
|
+
end # it
|
86
|
+
end # context
|
87
|
+
|
88
|
+
end # each
|
89
|
+
|
90
|
+
end # describe
|
91
|
+
end # describe
|
92
|
+
|
93
|
+
describe "parsing with automatic format detection" do
|
94
|
+
{
|
95
|
+
"11.0.8" => Mixlib::Versioning::Format::SemVer,
|
96
|
+
"11.0.8-1" => Mixlib::Versioning::Format::SemVer,
|
97
|
+
"11.0.8.rc.1" => Mixlib::Versioning::Format::Rubygems,
|
98
|
+
"11.0.8.rc.1-1" => Mixlib::Versioning::Format::Rubygems,
|
99
|
+
"11.0.8-rc.1" => Mixlib::Versioning::Format::OpscodeSemVer,
|
100
|
+
|
101
|
+
"10.18.2" => Mixlib::Versioning::Format::SemVer,
|
102
|
+
"10.18.2-poop" => Mixlib::Versioning::Format::SemVer,
|
103
|
+
"10.18.2.poop" => Mixlib::Versioning::Format::Rubygems,
|
104
|
+
"10.18.2.poop-1" => Mixlib::Versioning::Format::Rubygems,
|
105
|
+
|
106
|
+
"12.1.1+20130311134422" => Mixlib::Versioning::Format::OpscodeSemVer,
|
107
|
+
"12.1.1-rc.3+20130311134422" => Mixlib::Versioning::Format::OpscodeSemVer,
|
108
|
+
"12.1.1+20130308110833.git.2.94a1dde" => Mixlib::Versioning::Format::OpscodeSemVer,
|
109
|
+
|
110
|
+
"10.16.2-49-g21353f0" => Mixlib::Versioning::Format::GitDescribe,
|
111
|
+
"10.16.2-49-g21353f0-1" => Mixlib::Versioning::Format::GitDescribe,
|
112
|
+
"10.16.2.rc.2-49-g21353f0" => Mixlib::Versioning::Format::GitDescribe,
|
113
|
+
"10.16.2-rc.2-49-g21353f0" => Mixlib::Versioning::Format::GitDescribe,
|
114
|
+
}.each_pair do |version_string, expected_format|
|
115
|
+
|
116
|
+
context version_string do
|
117
|
+
let(:version_string){ version_string }
|
118
|
+
it "parses version string as: #{expected_format}" do
|
119
|
+
subject.parse(version_string).should be_a(expected_format)
|
120
|
+
end # it
|
121
|
+
end # context
|
122
|
+
|
123
|
+
end # each_pair
|
124
|
+
|
125
|
+
describe "version_string cannot be parsed" do
|
126
|
+
let(:version_string){ "A.B.C" }
|
127
|
+
it "returns nil" do
|
128
|
+
subject.parse(version_string).should be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end # describe "parsing with automatic format detection"
|
133
|
+
|
134
|
+
describe "parsing an Mixlib::Versioning::Format object" do
|
135
|
+
it "returns the same object" do
|
136
|
+
v = Mixlib::Versioning.parse(version_string)
|
137
|
+
result = subject.parse(v)
|
138
|
+
v.should be result
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end # describe .parse
|
143
|
+
|
144
|
+
describe ".find_target_version" do
|
145
|
+
let(:all_versions){%w{
|
146
|
+
11.0.0-beta.1
|
147
|
+
11.0.0-rc.1
|
148
|
+
11.0.0
|
149
|
+
11.0.1
|
150
|
+
11.0.1+2013031116332
|
151
|
+
11.0.2-alpha.0
|
152
|
+
11.0.2-alpha.0+2013041116332
|
153
|
+
11.0.2
|
154
|
+
}}
|
155
|
+
let(:filter_version){ nil }
|
156
|
+
let(:use_prerelease_versions){ false }
|
157
|
+
let(:use_build_versions){ false }
|
158
|
+
let(:subject_find) do
|
159
|
+
subject.find_target_version(all_versions,
|
160
|
+
filter_version,
|
161
|
+
use_prerelease_versions,
|
162
|
+
use_build_versions)
|
163
|
+
end
|
164
|
+
|
165
|
+
{
|
166
|
+
nil => {
|
167
|
+
:releases_only => "11.0.2",
|
168
|
+
:prerelease_versions => "11.0.2-alpha.0",
|
169
|
+
:build_versions => "11.0.1+2013031116332",
|
170
|
+
:prerelease_and_build_versions => "11.0.2-alpha.0+2013041116332"
|
171
|
+
},
|
172
|
+
"11.0.0" => {
|
173
|
+
:releases_only => "11.0.0",
|
174
|
+
:prerelease_versions => "11.0.0-rc.1",
|
175
|
+
:build_versions => nil,
|
176
|
+
:prerelease_and_build_versions => nil
|
177
|
+
},
|
178
|
+
"11.0.2" => {
|
179
|
+
:releases_only => "11.0.2",
|
180
|
+
:prerelease_versions => "11.0.2-alpha.0",
|
181
|
+
:build_versions => nil,
|
182
|
+
:prerelease_and_build_versions => "11.0.2-alpha.0+2013041116332"
|
183
|
+
},
|
184
|
+
"11.0.2" => {
|
185
|
+
:releases_only => "11.0.2",
|
186
|
+
:prerelease_versions => "11.0.2-alpha.0",
|
187
|
+
:build_versions => nil,
|
188
|
+
:prerelease_and_build_versions => "11.0.2-alpha.0+2013041116332"
|
189
|
+
},
|
190
|
+
"11.0.2-alpha.0" => {
|
191
|
+
:releases_only => "11.0.2-alpha.0",
|
192
|
+
:prerelease_versions => "11.0.2-alpha.0",
|
193
|
+
:build_versions => "11.0.2-alpha.0+2013041116332",
|
194
|
+
:prerelease_and_build_versions => "11.0.2-alpha.0+2013041116332"
|
195
|
+
}
|
196
|
+
}.each_pair do |filter_version, options|
|
197
|
+
|
198
|
+
context "filter version of: #{filter_version}" do
|
199
|
+
let(:filter_version){ filter_version }
|
200
|
+
let(:expected_version){ options[:releases_only] }
|
201
|
+
|
202
|
+
it "finds the most recent release version" do
|
203
|
+
subject_find.should eq Mixlib::Versioning.parse(expected_version)
|
204
|
+
end
|
205
|
+
|
206
|
+
context "include pre-release versions" do
|
207
|
+
let(:use_prerelease_versions){ true }
|
208
|
+
let(:expected_version){ options[:prerelease_versions] }
|
209
|
+
|
210
|
+
it "finds the most recent pre-release version" do
|
211
|
+
subject_find.should eq Mixlib::Versioning.parse(expected_version)
|
212
|
+
end # it
|
213
|
+
end # context
|
214
|
+
|
215
|
+
context "include build versions" do
|
216
|
+
let(:use_build_versions){ true }
|
217
|
+
let(:expected_version){ options[:build_versions] }
|
218
|
+
|
219
|
+
it "finds the most recent build version" do
|
220
|
+
subject_find.should eq Mixlib::Versioning.parse(expected_version)
|
221
|
+
end # it
|
222
|
+
end # context
|
223
|
+
|
224
|
+
context "include pre-release and build versions" do
|
225
|
+
let(:use_prerelease_versions){ true }
|
226
|
+
let(:use_build_versions){ true }
|
227
|
+
let(:expected_version){ options[:prerelease_and_build_versions] }
|
228
|
+
|
229
|
+
it "finds the most recent pre-release build version" do
|
230
|
+
subject_find.should eq Mixlib::Versioning.parse(expected_version)
|
231
|
+
end # it
|
232
|
+
end # context
|
233
|
+
|
234
|
+
end # context
|
235
|
+
end # each_pair
|
236
|
+
|
237
|
+
describe "all_versions argument is a mix of String and Mixlib::Versioning::Format instances" do
|
238
|
+
let(:all_versions){[
|
239
|
+
"11.0.0-beta.1",
|
240
|
+
"11.0.0-rc.1",
|
241
|
+
Mixlib::Versioning.parse("11.0.0")
|
242
|
+
]}
|
243
|
+
|
244
|
+
it "correctly parses the array" do
|
245
|
+
subject_find.should eq Mixlib::Versioning.parse("11.0.0")
|
246
|
+
end
|
247
|
+
end # describe
|
248
|
+
|
249
|
+
describe "filter_version argument is an instance of Mixlib::Versioning::Format" do
|
250
|
+
let(:filter_version){ Mixlib::Versioning::Format::SemVer.new("11.0.0") }
|
251
|
+
|
252
|
+
it "finds the correct version" do
|
253
|
+
subject_find.should eq Mixlib::Versioning.parse("11.0.0")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
end # describe
|
258
|
+
|
259
|
+
end # describe Mixlib::Versioning
|