Skip to content

Commit

Permalink
Merge pull request puppetlabs-toy-chest#5 from jeffmccune/ticket/mast…
Browse files Browse the repository at this point in the history
…er/4_semver_support

Ticket/master/4 semver support
  • Loading branch information
Jeff McCune committed Jun 21, 2011
2 parents ea24515 + 89b7d1c commit e028826
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/puppet/module/tool/applications/application.rb
Expand Up @@ -70,14 +70,12 @@ def parse_filename!
unless @username && @module_name
abort "Username and Module name not provided"
end
begin
Gem::Version.new(@version)
rescue ArgumentError => e
abort "Invalid version format: #{@version}"
if @version !~ /^(\d+)\.(\d+)\.(\d+)$|^(\d)+\.(\d)+\.(\d+)([a-zA-Z][a-zA-Z0-9-]*)$/ then
abort "Invalid version format: #{@version} (Semantic Versions are acceptable: http://semver.org)"
end
end
end

end

end
33 changes: 33 additions & 0 deletions spec/unit/semver_spec.rb
@@ -0,0 +1,33 @@
# Tested this spec test with rspec 2.5.1

require 'puppet/module/tool'

describe Puppet::Module::Tool::Applications::Application do

describe 'app' do

good_versions = %w{ 1.2.4 0.0.1 0.0.0 0.0.2git-8-g3d316d1 0.0.3b1 10.100.10000
0.1.2rc1 0.1.2dev-1 0.1.2svn12345 }
bad_versions = %w{ 0.1.2-3 0.1 0 0.1.2.3 dev }

before do
@app = Class.new(described_class).new
end

good_versions.each do |ver|
it "should accept version string #{ver}" do
@app.instance_eval("@filename=%q{puppetlabs-ntp-#{ver}}")
@app.parse_filename!
end
end

bad_versions.each do |ver|
it "should not accept version string #{ver}" do
@app.instance_eval("@filename=%q{puppetlabs-ntp-#{ver}}")
lambda { @app.parse_filename! }.should raise_error
end
end

end

end

0 comments on commit e028826

Please sign in to comment.