step-up 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # LastVersion: a project to versioning projects
2
+
3
+ LastVersion is an utility to manage versioning tags on git projects.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.rspec_opts = %w(-fs --color)
7
+ t.ruby_opts = %w(-w)
8
+ end
9
+ rescue LoadError
10
+ task :spec do
11
+ abort "Run `rake spec:deps` to be able to run the specs"
12
+ end
13
+
14
+ namespace :spec do
15
+ desc "Ensure spec dependencies are installed"
16
+ task :deps do
17
+ sh "gem list rspec | (grep 'rspec (2.0' 1> /dev/null) || gem install rspec --no-ri --no-rdoc"
18
+ end
19
+ end
20
+ end
21
+
22
+ desc "Build the gem"
23
+ task :build do
24
+ opers = Dir.glob('*.gem')
25
+ opers = ["rm #{ opers.join(' ') }"] unless opers.empty?
26
+ opers << ["gem build step-up.gemspec"]
27
+ sh opers.join(" && ")
28
+ end
29
+
30
+ desc "Build and install the gem, removing old installation"
31
+ task :install => :build do
32
+ gem = Dir.glob('*.gem').first
33
+ if gem.nil?
34
+ puts "could not install the gem"
35
+ else
36
+ sh "gem uninstall step-up && gem install #{ gem }"
37
+ end
38
+ end
39
+
40
+ task :default => :spec
data/bin/stepup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'step-up/cli'
4
+
5
+ begin
6
+ StepUp::CLI.start
7
+ rescue Exception => e
8
+ puts e.message
9
+ end
data/lib/step-up.rb ADDED
@@ -0,0 +1,11 @@
1
+ module StepUp
2
+ autoload :CONFIG, 'step-up/config.rb'
3
+ autoload :VERSION, 'step-up/version.rb'
4
+ module Driver
5
+ autoload :Git, 'step-up/driver/git.rb'
6
+ end
7
+ autoload :GitExtensions, 'step-up/git_extensions.rb'
8
+ module Parser
9
+ autoload :VersionMask, 'step-up/parser/version_mask.rb'
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ require 'thor'
2
+ require 'step-up'
3
+
4
+ module StepUp
5
+ class CLI < Thor
6
+ map %w(--version -v) => :gem_version
7
+
8
+ default_task :version
9
+
10
+ desc "", "show the last version of the application"
11
+ def version
12
+ puts StepUp::Driver::Git.last_version
13
+ end
14
+
15
+ desc "notes [object]", "show notes for the next version"
16
+ method_options :clean => :boolean
17
+ def notes(commit_base = nil)
18
+ puts StepUp::Driver::Git.unversioned_notes(commit_base, options[:clean])
19
+ end
20
+
21
+ desc "-v, --version", "show the last version of the gem"
22
+ def gem_version
23
+ puts StepUp::VERSION
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ module StepUp
3
+ CONFIG = {}
4
+
5
+ def self.load_config path
6
+ return CONFIG unless File.exists? path
7
+ CONFIG.merge! YAML.load_file(path)
8
+ rescue TypeError => e
9
+ puts "could not load #{path}: #{e.inspect}"
10
+ end
11
+
12
+ load_config File.expand_path('../config/step-up.yml', __FILE__)
13
+ load_config '.versionrc' # from working folder
14
+ end
@@ -0,0 +1,19 @@
1
+ notes:
2
+ after_versioned:
3
+ strategy: "remove"
4
+ #strategy: "keep"
5
+ section: "versioning"
6
+ changelog_message: "available on {version}"
7
+ sections:
8
+ - changes
9
+ - bugfixes
10
+ - features
11
+ - deploy_steps
12
+ versioning:
13
+ version_mask: "v0.0.0.9.rc9"
14
+ version_parts:
15
+ - major
16
+ - minor
17
+ - tiny
18
+ - patch
19
+ - rc
@@ -0,0 +1,83 @@
1
+ module StepUp
2
+ module Driver
3
+ class Git
4
+ include GitExtensions::Notes
5
+ attr_reader :mask
6
+ def initialize
7
+ @mask = Parser::VersionMask.new(CONFIG["versioning"]["version_mask"])
8
+ end
9
+
10
+ def self.last_version(commit_base = nil)
11
+ @driver ||= new
12
+ @driver.last_version_tag(commit_base) || "%s%s" % [@driver.mask.blank, '+']
13
+ end
14
+
15
+ def self.unversioned_notes(commit_base = nil, clean = false)
16
+ options = {:mode => :with_objects}
17
+ options.delete :mode if clean
18
+ new.all_objects_with_notes(commit_base).unversioned_only.to_changelog(options)
19
+ end
20
+
21
+ def commit_history(commit_base, top = nil)
22
+ top = "-n#{ top }" unless top.nil?
23
+ `git log --pretty=oneline --no-color --no-notes #{ top } #{ commit_base }`.gsub(/^(\w+)\s.*$/, '\1').split("\n")
24
+ end
25
+
26
+ def all_tags
27
+ `git tag -l`.split("\n")
28
+ end
29
+
30
+ def objects_with_notes_of(ref)
31
+ `git notes --ref=#{ ref } list`.gsub(/^\w+\s(\w+)$/, '\1').split(/\n/)
32
+ end
33
+
34
+ def all_objects_with_notes(commit_base = nil)
35
+ objects = commit_history(commit_base)
36
+ objects_with_notes = {}.extend GitExtensions::NotesTransformation
37
+ objects_with_notes.driver = self
38
+ notes_sections.each do |section|
39
+ obj = objects_with_notes_of(section)
40
+ obj = obj.collect { |object|
41
+ pos = objects.index(object)
42
+ pos.nil? ? nil : [pos, object]
43
+ }.compact.sort.reverse
44
+ objects_with_notes[section] = obj.collect{ |o| o.last }
45
+ end
46
+ objects_with_notes
47
+ end
48
+
49
+ def note_message(ref, commit)
50
+ `git notes --ref=#{ ref } show #{ commit }`
51
+ end
52
+
53
+ def notes_messages(objects_with_notes)
54
+ objects_with_notes.messages
55
+ end
56
+
57
+ def all_version_tags
58
+ @version_tags ||= all_tags.map{ |tag| mask.parse(tag) }.compact.sort.map{ |tag| mask.format(tag) }.reverse
59
+ end
60
+
61
+ def increase_version_tag(part, commit_base = nil)
62
+ commands = []
63
+ tag = last_version_tag(commit_base)
64
+ tag = tag.sub(/\+$/, '')
65
+ tag = mask.increase_version(tag, part)
66
+ message = all_objects_with_notes(commit_base)
67
+ commands << "git fetch"
68
+ commands << "git tag -a -m \"#{ message.to_changelog }\" #{ tag }"
69
+ commands << "git push --tags"
70
+ commands + steps_for_archiving_notes(message, tag)
71
+ end
72
+
73
+ def last_version_tag(commit_base = nil)
74
+ objects = commit_history(commit_base)
75
+ all_version_tags.each do |tag|
76
+ index = objects.index(commit_history(tag, 1).first)
77
+ return "#{ tag }#{ '+' unless index.zero? }" unless index.nil?
78
+ end
79
+ nil
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,130 @@
1
+ module StepUp
2
+ module GitExtensions
3
+ NOTES_STRATEGIES = {}
4
+ def self.register_notes_strategy(key, instance)
5
+ NOTES_STRATEGIES[key] = instance
6
+ end
7
+
8
+ module Notes
9
+ def steps_for_archiving_notes(objects_with_notes, tag)
10
+ strategy = notes_after_versioned["strategy"]
11
+ raise ArgumentError, "unknown strategy: #{ strategy }" unless NOTES_STRATEGIES.include?(strategy)
12
+ NOTES_STRATEGIES[strategy].steps_for_archiving_notes(objects_with_notes, tag, self)
13
+ end
14
+
15
+ private
16
+
17
+ def notes_sections
18
+ CONFIG["notes"]["sections"]
19
+ end
20
+
21
+ def notes_after_versioned
22
+ CONFIG["notes"]["after_versioned"]
23
+ end
24
+ end
25
+
26
+ module NotesTransformation
27
+ def self.extend_object(base)
28
+ super
29
+ class << base
30
+ attr_writer :driver, :parent, :kept_notes
31
+ def []=(p1, p2)
32
+ super
33
+ sections << p1 unless sections.include?(p1)
34
+ end
35
+ end
36
+ end
37
+
38
+ def driver
39
+ @driver ||= parent.driver
40
+ end
41
+
42
+ def sections
43
+ @sections ||= parent != self && parent.sections && parent.sections.dup || []
44
+ end
45
+
46
+ def parent
47
+ @parent ||= self
48
+ end
49
+
50
+ def kept_notes
51
+ @kept_notes ||= driver.objects_with_notes_of(kept_notes_section)
52
+ end
53
+
54
+ def kept_notes_section
55
+ driver.send(:notes_after_versioned)["section"]
56
+ end
57
+
58
+ def unversioned_only
59
+ notes = {}.extend NotesTransformation
60
+ notes.driver = driver
61
+ notes.kept_notes = kept_notes
62
+ sections.each do |section|
63
+ notes[section] = (parent[section] || []).select{ |commit| not kept_notes.include?(commit) }
64
+ end
65
+ notes
66
+ end
67
+
68
+ def messages
69
+ unless defined? @messages
70
+ notes = {}.extend NotesTransformation
71
+ notes.parent = self
72
+ sections.each do |section|
73
+ notes[section] = (parent[section] || []).map{ |commit| driver.note_message(section, commit) }
74
+ end
75
+ @messages = notes
76
+ end
77
+ @messages
78
+ end
79
+
80
+ def to_changelog(options = {})
81
+ changelog = []
82
+ sections.each_with_index do |section, index|
83
+ changelog << "#{ section.capitalize.gsub(/_/, ' ') }:\n" unless index.zero? || messages[section].empty?
84
+ messages[section].each_with_index do |note, index|
85
+ note = note.sub(/$/, " (#{ parent[section][index] })") if options[:mode] == :with_objects
86
+ changelog += note.split(/\n+/).collect{ |line| line.sub(/^(\s*)/, '\1 - ') }
87
+ end
88
+ changelog << "" unless messages[section].empty?
89
+ end
90
+ changelog.join("\n")
91
+ end
92
+ end
93
+
94
+ module Strategy
95
+ class RemoveNotes
96
+ def steps_for_archiving_notes(objects_with_notes, tag, driver)
97
+ commands = []
98
+ objects_with_notes.sections.each do |section|
99
+ objects_with_notes[section].each do |object|
100
+ commands << "git notes --ref=#{ section } remove #{ object }"
101
+ end
102
+ commands << "git push origin refs/notes/#{ section }" unless objects_with_notes[section].empty?
103
+ end
104
+ commands
105
+ end
106
+ end
107
+
108
+ class KeepNotes
109
+ def steps_for_archiving_notes(objects_with_notes, tag, driver)
110
+ commands = []
111
+ objects = []
112
+ changelog_message = driver.notes_after_versioned["changelog_message"]
113
+ objects_with_notes.sections.each do |section|
114
+ objects_with_notes[section].each do |object|
115
+ unless objects.include?(object)
116
+ objects << object
117
+ kept_message = changelog_message.gsub(/\{version\}/, tag)
118
+ commands << "git notes --ref=#{ driver.notes_after_versioned["section"] } add -m \"#{ kept_message }\" #{ object }"
119
+ end
120
+ end
121
+ end
122
+ commands << "git push origin refs/notes/#{ driver.notes_after_versioned["section"] }" unless objects.empty?
123
+ commands
124
+ end
125
+ end
126
+ end
127
+ register_notes_strategy "remove", Strategy::RemoveNotes.new
128
+ register_notes_strategy "keep", Strategy::KeepNotes.new
129
+ end
130
+ end
@@ -0,0 +1,73 @@
1
+ module StepUp
2
+ module Parser
3
+ class VersionMask
4
+ attr_reader :mask
5
+ attr_reader :iterator
6
+ def initialize(mask)
7
+ @mask = mask.scan(/\D+[09]/)
8
+ raise ArgumentError if mask != @mask.join
9
+ @iterator = @mask.map do |token|
10
+ Regexp.new token.sub(/\./, '\\.').sub(/[09]$/,'(\d+)')
11
+ end
12
+ end
13
+
14
+ def parse(version)
15
+ return unless version.is_a?(String)
16
+ i = 0
17
+ v = []
18
+ iterator.each_with_index do |pattern, index|
19
+ pos = version.index(pattern, i)
20
+ if pos.nil?
21
+ if mask[index] =~ /9$/
22
+ v << 0
23
+ else
24
+ return
25
+ end
26
+ else
27
+ if pos == i
28
+ n = $1
29
+ i += mask[index].size + n.size - 1
30
+ v << n.to_i
31
+ elsif mask[index] =~ /9$/
32
+ v << 0
33
+ else
34
+ return
35
+ end
36
+ end
37
+ end
38
+ v
39
+ end
40
+
41
+ def format(version)
42
+ raise ArgumentError unless version.is_a?(Array) && version.size == mask.size
43
+ v = []
44
+ iterator.each_with_index do |pattern, index|
45
+ raise ArgumentError unless version[index].is_a?(Fixnum)
46
+ unless version[index].zero? && mask[index] =~ /9$/
47
+ v << mask[index].sub(/[09]$/, version[index].to_s)
48
+ end
49
+ end
50
+ v.join
51
+ end
52
+
53
+ def increase_version(version, part)
54
+ v = parse version
55
+ part = version_parts.index(part)
56
+ (v.size-part).times do |index|
57
+ v[part+index] = (index.zero? ? v[part+index]+1 : 0)
58
+ end
59
+ format v
60
+ end
61
+
62
+ def blank
63
+ format mask.size.times.map{ 0 }
64
+ end
65
+
66
+ private
67
+
68
+ def version_parts
69
+ CONFIG["versioning"]["version_parts"]
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ module StepUp
2
+ path = File.expand_path('../..', __FILE__)
3
+ v = nil
4
+ if path =~ /\/step-up-([\w\.\-]+)/
5
+ v = $1
6
+ end
7
+ if v.nil?
8
+ $:.each do |path|
9
+ if path =~ /\/step-up-([\w\.\-]+)/
10
+ v = $1
11
+ break
12
+ end
13
+ end
14
+ end
15
+ if v.nil?
16
+ path = File.expand_path('../../../.git', __FILE__)
17
+ if File.exists?(path)
18
+ v = Driver::Git.last_version
19
+ end
20
+ end
21
+ if v.nil?
22
+ VERSION = "0.0.0"
23
+ else
24
+ v.sub!(/^v/, '')
25
+ v.sub!(/\+$/, '')
26
+ VERSION = v
27
+ end
28
+ end
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe StepUp::Driver::Git do
4
+ before do
5
+ @driver = StepUp::Driver::Git.new
6
+ end
7
+
8
+
9
+ context 'fetching information' do
10
+ it 'should get all commits from history log' do
11
+ @driver.should respond_to :commit_history
12
+ @driver.commit_history("f4cfcc2").should be == ["f4cfcc2c8b1f7edb1b7817b4e8a9063d21db089b", "2fb8a3281fb6777405aadcd699adb852b615a3e4", "d7b0fa26ca547b963569d7a82afd7d7ca11b71ae", "8b38f7c842496fd50b4e1b7ca5e883940b9cbf83", "f76c8d7bf64678963aeef84009be54f1819e3389", "8299243c7dac8f27c3572424a348a7f83ef0ce28", "570fe2e6e7f0b06140ae109e50a1e86628819493", "cdd4d5aa885b22136f4a08c1b35076f888f9536e", "72174c160b50ec73a8f67c8150e0dcd976857411", "b2da007b4fb35e0274858c14a83a836852d055a4", "4f0e7e0f6b3df2d49ed0029ed01998bf2102b28f"]
13
+ @driver.commit_history("f4cfcc2", 3).should be == ["f4cfcc2c8b1f7edb1b7817b4e8a9063d21db089b", "2fb8a3281fb6777405aadcd699adb852b615a3e4", "d7b0fa26ca547b963569d7a82afd7d7ca11b71ae"]
14
+ end
15
+ end
16
+
17
+
18
+ context 'fetching tags' do
19
+ it "should get tags sorted" do
20
+ tags = %w[note-v0.2.0-1 v0.1.0 v0.1.1 v0.1.2 v0.1.1.rc3]
21
+ @driver.stubs(:all_tags).returns(tags)
22
+ @driver.all_version_tags.should be == %w[v0.1.2 v0.1.1.rc3 v0.1.1 v0.1.0]
23
+ end
24
+
25
+ it "should return last tag visible" do
26
+ @driver.last_version_tag("f4cfcc2").should be == "v0.0.1+"
27
+ @driver.last_version_tag("570fe2e").should be == "v0.0.1"
28
+ @driver.class.last_version("f4cfcc2").should be == "v0.0.1+"
29
+ @driver.class.last_version("570fe2e").should be == "v0.0.1"
30
+ end
31
+
32
+ it "should get no tag visible" do
33
+ @driver.last_version_tag("cdd4d5a").should be_nil
34
+ end
35
+
36
+ it "should get a blank tag" do
37
+ @driver.mask.blank.should be == "v0.0.0"
38
+ @driver.class.last_version("cdd4d5a").should be == "v0.0.0+"
39
+ end
40
+ end
41
+
42
+
43
+ context "fetching notes" do
44
+ context "from test_* sections" do
45
+ before do
46
+ @driver.stubs(:notes_sections).returns(%w[test_changes test_bugfixes test_features])
47
+ @objects_with_notes = {"test_changes" => ["8299243c7dac8f27c3572424a348a7f83ef0ce28", "2fb8a3281fb6777405aadcd699adb852b615a3e4"], "test_bugfixes" => ["d7b0fa26ca547b963569d7a82afd7d7ca11b71ae"], "test_features" => []}
48
+ @messages = {"test_changes" => ["removing files from gemspec\n .gitignore\n lastversion.gemspec\n", "loading default configuration yaml\n\nloading external configuration yaml\n"], "test_bugfixes" => ["sorting tags according to the mask parser\n"], "test_features" => []}
49
+ @changelog_full = <<-MSG
50
+ - removing files from gemspec (8299243c7dac8f27c3572424a348a7f83ef0ce28)
51
+ - .gitignore
52
+ - lastversion.gemspec
53
+ - loading default configuration yaml (2fb8a3281fb6777405aadcd699adb852b615a3e4)
54
+ - loading external configuration yaml
55
+
56
+ Test bugfixes:
57
+
58
+ - sorting tags according to the mask parser (d7b0fa26ca547b963569d7a82afd7d7ca11b71ae)
59
+ MSG
60
+ @changelog = @changelog_full.gsub(/\s\(\w+\)$/, '')
61
+ @all_objects_with_notes = @driver.all_objects_with_notes("f4cfcc2")
62
+ end
63
+ it "should get all objects with notes" do
64
+ @all_objects_with_notes.should be == @objects_with_notes
65
+ end
66
+ it "should get all notes messages" do
67
+ @all_objects_with_notes.should respond_to(:messages)
68
+ @all_objects_with_notes.messages.should be == @messages
69
+ end
70
+ it "should get changelog message" do
71
+ @all_objects_with_notes.should respond_to(:to_changelog)
72
+ @all_objects_with_notes.sections.should be == @driver.notes_sections
73
+ @all_objects_with_notes.messages.should be == @messages
74
+ @all_objects_with_notes.messages.to_changelog.should be == @changelog
75
+ @all_objects_with_notes.to_changelog.should be == @changelog
76
+ @all_objects_with_notes.messages.to_changelog(:mode => :with_objects).should be == @changelog_full
77
+ @all_objects_with_notes.to_changelog(:mode => :with_objects).should be == @changelog_full
78
+ end
79
+ it "should get unversioned changelog message" do
80
+ @all_objects_with_notes.should be == @objects_with_notes
81
+ object = @objects_with_notes["test_changes"].shift
82
+ @all_objects_with_notes.stubs(:kept_notes).returns([object])
83
+ @all_objects_with_notes.should respond_to(:unversioned_only)
84
+ @all_objects_with_notes.unversioned_only.should be == @objects_with_notes
85
+ end
86
+ end
87
+ end
88
+
89
+
90
+ context "increasing version" do
91
+ before do
92
+ @driver.stubs(:notes_sections).returns(%w[test_changes test_bugfixes test_features])
93
+ end
94
+
95
+
96
+ context "using 'remove' as after_versioned:strategy" do
97
+ before do
98
+ @driver.stubs(:notes_after_versioned).returns({"strategy" => "remove", "section" => "test_versioning", "changelog_message" => "available on {version}"})
99
+ @steps = <<-STEPS
100
+ git fetch
101
+
102
+ git tag -a -m " - removing files from gemspec
103
+ - .gitignore
104
+ - lastversion.gemspec
105
+ - loading default configuration yaml
106
+ - loading external configuration yaml
107
+
108
+ Test bugfixes:
109
+
110
+ - sorting tags according to the mask parser
111
+ " v0.1.0
112
+
113
+ git push --tags
114
+
115
+ git notes --ref=test_changes remove 8299243c7dac8f27c3572424a348a7f83ef0ce28
116
+
117
+ git notes --ref=test_changes remove 2fb8a3281fb6777405aadcd699adb852b615a3e4
118
+
119
+ git push origin refs/notes/test_changes
120
+
121
+ git notes --ref=test_bugfixes remove d7b0fa26ca547b963569d7a82afd7d7ca11b71ae
122
+
123
+ git push origin refs/notes/test_bugfixes
124
+ STEPS
125
+ @steps = @steps.chomp.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
126
+ end
127
+ it "should return steps" do
128
+ @driver.should respond_to :increase_version_tag
129
+ @driver.increase_version_tag("minor", "f4cfcc2").should be == @steps
130
+ end
131
+ end
132
+
133
+
134
+ context "using 'keep' as after_versioned:strategy" do
135
+ before do
136
+ @driver.stubs(:notes_after_versioned).returns({"strategy" => "keep", "section" => "test_versioning", "changelog_message" => "available on {version}"})
137
+ @steps = <<-STEPS
138
+ git fetch
139
+
140
+ git tag -a -m " - removing files from gemspec
141
+ - .gitignore
142
+ - lastversion.gemspec
143
+ - loading default configuration yaml
144
+ - loading external configuration yaml
145
+
146
+ Test bugfixes:
147
+
148
+ - sorting tags according to the mask parser
149
+ " v0.1.0
150
+
151
+ git push --tags
152
+
153
+ git notes --ref=test_versioning add -m "available on v0.1.0" 8299243c7dac8f27c3572424a348a7f83ef0ce28
154
+
155
+ git notes --ref=test_versioning add -m "available on v0.1.0" 2fb8a3281fb6777405aadcd699adb852b615a3e4
156
+
157
+ git notes --ref=test_versioning add -m "available on v0.1.0" d7b0fa26ca547b963569d7a82afd7d7ca11b71ae
158
+
159
+ git push origin refs/notes/test_versioning
160
+ STEPS
161
+ @steps = @steps.chomp.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
162
+ end
163
+ it "should return steps" do
164
+ @driver.should respond_to :increase_version_tag
165
+ @driver.increase_version_tag("minor", "f4cfcc2").should be == @steps
166
+ end
167
+ end
168
+ end
169
+
170
+
171
+ context "checking helper methods" do
172
+ it "should load default notes' sections" do
173
+ @driver.send(:notes_sections).should be == StepUp::CONFIG["notes"]["sections"]
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe StepUp::Parser::VersionMask do
4
+ before do
5
+ lambda {
6
+ @mask = StepUp::Parser::VersionMask.new("v0.0.0.9.9.rc9")
7
+ }.should_not raise_error ArgumentError
8
+ end
9
+
10
+
11
+ context "parsing" do
12
+ it "should parse" do
13
+ @mask.parse("v0.1.0.rc3").should be == [0, 1, 0, 0, 0, 3]
14
+ @mask.parse("v0.1.0").should be == [0, 1, 0, 0, 0, 0]
15
+ @mask.parse("v0.1.4.5.rc3").should be == [0, 1, 4, 5, 0, 3]
16
+ end
17
+ it "should not parse" do
18
+ @mask.parse("v0.1.rc3").should be_nil
19
+ @mask.parse("note-v0.1.0-1").should be_nil
20
+ end
21
+ end
22
+
23
+
24
+ context "formatting" do
25
+ it "should format" do
26
+ @mask.format([0, 1, 0, 0, 0, 3]).should be == "v0.1.0.rc3"
27
+ @mask.format([0, 1, 0, 0, 0, 0]).should be == "v0.1.0"
28
+ @mask.format([0, 1, 4, 5, 0, 3]).should be == "v0.1.4.5.rc3"
29
+ end
30
+ it "should not format" do
31
+ lambda {@mask.format([0, 1, 0, 0, 3])}.should raise_error ArgumentError
32
+ lambda {@mask.format([0, 1, 0, 0, 0, 0, 0])}.should raise_error ArgumentError
33
+ end
34
+ end
35
+
36
+
37
+ context "increasing version" do
38
+ before do
39
+ @mask.stubs(:version_parts).returns(%w[major minor tiny patch build rc])
40
+ end
41
+ it "should increase by parts" do
42
+ version = "v2.3.1.6.4.rc5"
43
+ @mask.increase_version(version, "major").should be == "v3.0.0"
44
+ @mask.increase_version(version, "minor").should be == "v2.4.0"
45
+ @mask.increase_version(version, "tiny").should be == "v2.3.2"
46
+ @mask.increase_version(version, "patch").should be == "v2.3.1.7"
47
+ @mask.increase_version(version, "build").should be == "v2.3.1.6.5"
48
+ @mask.increase_version(version, "rc").should be == "v2.3.1.6.4.rc6"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'step-up'
5
+ require 'rspec'
6
+
7
+ Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
8
+ require file
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.mock_with :mocha
13
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: step-up
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Marcelo Manzan
14
+ - Eric Adrien Fer
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-12-09 00:00:00 -02:00
20
+ default_executable: stepup
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: thor
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 43
31
+ segments:
32
+ - 0
33
+ - 14
34
+ - 6
35
+ version: 0.14.6
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: mocha
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: StepUp manages a project's versioning through its entire life
67
+ email:
68
+ - manzan@gmail.com
69
+ - eric.fer@gmail.com
70
+ executables:
71
+ - stepup
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - README.md
78
+ - Rakefile
79
+ - bin/stepup
80
+ - lib/step-up.rb
81
+ - lib/step-up/cli.rb
82
+ - lib/step-up/config.rb
83
+ - lib/step-up/config/step-up.yml
84
+ - lib/step-up/driver/git.rb
85
+ - lib/step-up/git_extensions.rb
86
+ - lib/step-up/parser/version_mask.rb
87
+ - lib/step-up/version.rb
88
+ - spec/lib/step-up/driver/git_spec.rb
89
+ - spec/lib/step-up/parser/version_mask_spec.rb
90
+ - spec/spec_helper.rb
91
+ has_rdoc: true
92
+ homepage: https://github.com/redoc/step-up
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 23
115
+ segments:
116
+ - 1
117
+ - 3
118
+ - 6
119
+ version: 1.3.6
120
+ requirements: []
121
+
122
+ rubyforge_project: step-up
123
+ rubygems_version: 1.3.7
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: The best way to manage your project's versioning
127
+ test_files:
128
+ - spec/lib/step-up/driver/git_spec.rb
129
+ - spec/lib/step-up/parser/version_mask_spec.rb
130
+ - spec/spec_helper.rb