mixlib-versioning 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/.gitignore +18 -0
  2. data/.yardopts +7 -0
  3. data/CHANGELOG.md +3 -0
  4. data/CONTRIBUTING.md +188 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE +201 -0
  7. data/README.md +364 -0
  8. data/Rakefile +6 -0
  9. data/lib/mixlib/versioning.rb +194 -0
  10. data/lib/mixlib/versioning/exceptions.rb +28 -0
  11. data/lib/mixlib/versioning/format.rb +351 -0
  12. data/lib/mixlib/versioning/format/git_describe.rb +71 -0
  13. data/lib/mixlib/versioning/format/opscode_semver.rb +91 -0
  14. data/lib/mixlib/versioning/format/rubygems.rb +66 -0
  15. data/lib/mixlib/versioning/format/semver.rb +66 -0
  16. data/lib/mixlib/versioning/version.rb +23 -0
  17. data/mixlib-versioning.gemspec +22 -0
  18. data/spec/mixlib/versioning/format/git_describe_spec.rb +178 -0
  19. data/spec/mixlib/versioning/format/opscode_semver_spec.rb +113 -0
  20. data/spec/mixlib/versioning/format/rubygems_spec.rb +142 -0
  21. data/spec/mixlib/versioning/format/semver_spec.rb +107 -0
  22. data/spec/mixlib/versioning/format_spec.rb +69 -0
  23. data/spec/mixlib/versioning/versioning_spec.rb +259 -0
  24. data/spec/spec_helper.rb +43 -0
  25. data/spec/support/shared_examples/basic_semver.rb +42 -0
  26. data/spec/support/shared_examples/behaviors/filterable.rb +66 -0
  27. data/spec/support/shared_examples/behaviors/parses_valid_version_strings.rb +32 -0
  28. data/spec/support/shared_examples/behaviors/rejects_invalid_version_strings.rb +32 -0
  29. data/spec/support/shared_examples/behaviors/serializable.rb +51 -0
  30. data/spec/support/shared_examples/behaviors/sortable.rb +45 -0
  31. data/spec/support/shared_examples/semver.rb +105 -0
  32. metadata +127 -0
@@ -0,0 +1,43 @@
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 'mixlib/versioning'
20
+
21
+ # load all shared examples and shared contexts
22
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
23
+ require(file)
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ # a little syntactic sugar
28
+ config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
29
+
30
+ # Use color in STDOUT
31
+ config.color_enabled = true
32
+
33
+ # Use color not only in STDOUT but also in pagers and files
34
+ config.tty = true
35
+
36
+ # run the examples in random order
37
+ config.order = :rand
38
+
39
+ # specify metadata with symobls only (ie no '=> true' required)
40
+ config.treat_symbols_as_metadata_keys_with_true_values = true
41
+ config.filter_run :focus => true
42
+ config.run_all_when_everything_filtered = true
43
+ end
@@ -0,0 +1,42 @@
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
+ 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
+ }
34
+ }
35
+
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"
40
+ }
41
+
42
+ end
@@ -0,0 +1,66 @@
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
+ shared_examples "filterable" do
20
+
21
+ let(:unsorted_versions) do
22
+ unsorted_version_strings.map{ |v| described_class.new(v) }
23
+ end
24
+
25
+ # 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
+ })
36
+ end # it
37
+
38
+ it "filters by pre-release versions only" do
39
+ filtered = unsorted_versions.select(&:prerelease?)
40
+ filtered.should eq(prerelease_versions.map{|v|
41
+ described_class.new(v)
42
+ })
43
+ end # it
44
+
45
+ it "filters by build versions only" do
46
+ filtered = unsorted_versions.select(&:build?)
47
+ filtered.should eq(build_versions.map{|v|
48
+ described_class.new(v)
49
+ })
50
+ end # it
51
+
52
+ it "filters by release build versions only" do
53
+ filtered = unsorted_versions.select(&:release_build?)
54
+ filtered.should eq(release_build_versions.map{|v|
55
+ described_class.new(v)
56
+ })
57
+ end # it
58
+
59
+ it "filters by pre-release build versions only" do
60
+ filtered = unsorted_versions.select(&:prerelease_build?)
61
+ filtered.should eq(prerelease_build_versions.map{|v|
62
+ described_class.new(v)
63
+ })
64
+ end # it
65
+
66
+ end # shared_examples
@@ -0,0 +1,32 @@
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
+ shared_examples "parses valid version strings" do |valid_examples|
20
+
21
+ valid_examples.each do |version, options|
22
+
23
+ context version do
24
+ let(:version_string){ version }
25
+
26
+ options.each_pair do |name, value|
27
+ its(name){ should eq value}
28
+ end
29
+
30
+ end # context
31
+ end # valid_examples
32
+ end # shared_examples
@@ -0,0 +1,32 @@
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
+ shared_examples "rejects invalid version strings" do |invalid_examples|
20
+
21
+ invalid_examples.each_pair do |version, reason|
22
+
23
+ context version do
24
+ let(:version_string){ version }
25
+
26
+ it "fails because: #{reason}" do
27
+ expect { subject }.to raise_error(Mixlib::Versioning::ParseError)
28
+ end
29
+
30
+ end # context
31
+ end # invalid_examples
32
+ end # shared_examples
@@ -0,0 +1,51 @@
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
+ shared_examples "serializable" do |version_strings|
20
+
21
+ describe "#to_s" do
22
+ version_strings.each do |v|
23
+ it "reconstructs the initial input for #{v}" do
24
+ described_class.new(v).to_s.should == v
25
+ end # it
26
+ end # version_strings
27
+ end # describe
28
+
29
+ describe "#to_semver_string" do
30
+ version_strings.each do |v|
31
+ it "generates a semver version string for #{v}" do
32
+ subject = described_class.new(v)
33
+ string = subject.to_semver_string
34
+ semver = Mixlib::Versioning::Format::SemVer.new(string)
35
+ string.should eq semver.to_s
36
+ end # it
37
+ end # version_strings
38
+ end # describe
39
+
40
+ describe "#to_rubygems_string" do
41
+ version_strings.each do |v|
42
+ it "generates a rubygems version string for #{v}" do
43
+ subject = described_class.new(v)
44
+ string = subject.to_rubygems_string
45
+ rubygems = Mixlib::Versioning::Format::Rubygems.new(string)
46
+ string.should eq rubygems.to_s
47
+ end # it
48
+ end # version_strings
49
+ end # describe
50
+
51
+ end # shared_examples
@@ -0,0 +1,45 @@
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
+ shared_examples "sortable" do
20
+
21
+ let(:unsorted_versions) do
22
+ unsorted_version_strings.map{ |v| described_class.new(v) }
23
+ end
24
+
25
+ let(:sorted_versions) do
26
+ sorted_version_strings.map{ |v| described_class.new(v) }
27
+ end
28
+
29
+ it 'responds to <=>' do
30
+ described_class.should respond_to(:<=>)
31
+ end
32
+
33
+ it "sorts all properly" do
34
+ unsorted_versions.sort.should eq sorted_versions
35
+ end
36
+
37
+ it "finds the min" do
38
+ unsorted_versions.min.should eq described_class.new(min)
39
+ end
40
+
41
+ it "finds the max" do
42
+ unsorted_versions.max.should eq described_class.new(max)
43
+ end
44
+
45
+ end # shared_examples
@@ -0,0 +1,105 @@
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 'mixlib/versioning'
20
+
21
+ shared_examples Mixlib::Versioning::Format::SemVer do
22
+
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
37
+ },
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
+ },
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
+ }
63
+
64
+ it_has_behavior "rejects invalid version strings", {
65
+ "8.8.8.8" => "too many segments: MAJOR.MINOR.PATCH.EXTRA"
66
+ }
67
+
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 }
76
+ end
77
+
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 }
85
+ end
86
+
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 }
94
+ end
95
+
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 }
103
+ end
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixlib-versioning
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Seth Chisamore
9
+ - Christopher Maier
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec_junit_formatter
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: General purpose Ruby library that allows you to parse, compare and manipulate
48
+ version strings in multiple formats.
49
+ email:
50
+ - schisamo@opscode.com
51
+ - cm@opscode.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - .yardopts
58
+ - CHANGELOG.md
59
+ - CONTRIBUTING.md
60
+ - Gemfile
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - lib/mixlib/versioning.rb
65
+ - lib/mixlib/versioning/exceptions.rb
66
+ - lib/mixlib/versioning/format.rb
67
+ - lib/mixlib/versioning/format/git_describe.rb
68
+ - lib/mixlib/versioning/format/opscode_semver.rb
69
+ - lib/mixlib/versioning/format/rubygems.rb
70
+ - lib/mixlib/versioning/format/semver.rb
71
+ - lib/mixlib/versioning/version.rb
72
+ - mixlib-versioning.gemspec
73
+ - spec/mixlib/versioning/format/git_describe_spec.rb
74
+ - spec/mixlib/versioning/format/opscode_semver_spec.rb
75
+ - spec/mixlib/versioning/format/rubygems_spec.rb
76
+ - spec/mixlib/versioning/format/semver_spec.rb
77
+ - spec/mixlib/versioning/format_spec.rb
78
+ - spec/mixlib/versioning/versioning_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/support/shared_examples/basic_semver.rb
81
+ - spec/support/shared_examples/behaviors/filterable.rb
82
+ - spec/support/shared_examples/behaviors/parses_valid_version_strings.rb
83
+ - spec/support/shared_examples/behaviors/rejects_invalid_version_strings.rb
84
+ - spec/support/shared_examples/behaviors/serializable.rb
85
+ - spec/support/shared_examples/behaviors/sortable.rb
86
+ - spec/support/shared_examples/semver.rb
87
+ homepage: https://github.com/opscode/mixlib-versioning
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.25
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: General purpose Ruby library that allows you to parse, compare and manipulate
111
+ version strings in multiple formats.
112
+ test_files:
113
+ - spec/mixlib/versioning/format/git_describe_spec.rb
114
+ - spec/mixlib/versioning/format/opscode_semver_spec.rb
115
+ - spec/mixlib/versioning/format/rubygems_spec.rb
116
+ - spec/mixlib/versioning/format/semver_spec.rb
117
+ - spec/mixlib/versioning/format_spec.rb
118
+ - spec/mixlib/versioning/versioning_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/support/shared_examples/basic_semver.rb
121
+ - spec/support/shared_examples/behaviors/filterable.rb
122
+ - spec/support/shared_examples/behaviors/parses_valid_version_strings.rb
123
+ - spec/support/shared_examples/behaviors/rejects_invalid_version_strings.rb
124
+ - spec/support/shared_examples/behaviors/serializable.rb
125
+ - spec/support/shared_examples/behaviors/sortable.rb
126
+ - spec/support/shared_examples/semver.rb
127
+ has_rdoc: