step-up 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,6 @@
1
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
2
+ version = nil
3
+ version = $1 if ::File.expand_path('../..', __FILE__) =~ /\/step-up-([\w\.\-]+)/
4
+ version = Driver::Git.new.last_version_tag if version.nil? && ::File.exists?(::File.expand_path('../../../.git', __FILE__))
5
+ VERSION = version.gsub(/^v?([^\+]+)\+?\d*$/, '\1')
28
6
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe StepUp::CONFIG do
4
+ before do
5
+ @c = StepUp::CONFIG
6
+ end
7
+
8
+ context "getting an attribute" do
9
+ it "that does not exists" do
10
+ lambda { @c.notes2 }.should raise_error(NoMethodError)
11
+ end
12
+ it "that exists" do
13
+ @c.should_not respond_to(:notes)
14
+ @c.notes.should be_kind_of(Hash)
15
+ @c.notes.should be_kind_of(StepUp::ConfigExt)
16
+ @c.notes.should_not respond_to(:sections)
17
+ @c.notes.sections.should be_kind_of(Array)
18
+ @c.notes.should_not respond_to(:after_versioned)
19
+ @c.notes.after_versioned.should be_kind_of(Hash)
20
+ @c.notes.after_versioned.should be_kind_of(StepUp::ConfigExt)
21
+ @c.notes.after_versioned.should_not respond_to(:section)
22
+ @c.notes.after_versioned.section.should be_kind_of(String)
23
+ end
24
+ end
25
+
26
+
27
+ context "getting notes sections" do
28
+ it "by names" do
29
+ @c.notes_sections.should be_kind_of(Array)
30
+ @c.notes_sections.should respond_to(:names)
31
+ @c.notes_sections.names.should be == %w[changes bugfixes features deploy_steps]
32
+ end
33
+
34
+ it "by prefixes" do
35
+ @c.notes_sections.should be_kind_of(Array)
36
+ @c.notes_sections.should respond_to(:prefixes)
37
+ @c.notes_sections.prefixes.should be == ["change: ", "bugfix: ", "feature: ", "deploy_step: "]
38
+ end
39
+
40
+ it "by labels" do
41
+ @c.notes_sections.should be_kind_of(Array)
42
+ @c.notes_sections.should respond_to(:labels)
43
+ @c.notes_sections.labels.should be == ["Changes:", "Bugfixes:", "Features:", "Deploy steps:"]
44
+ end
45
+ end
46
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'time'
2
3
 
3
4
  describe StepUp::Driver::Git do
4
5
  before do
@@ -12,94 +13,101 @@ describe StepUp::Driver::Git do
12
13
  @driver.commit_history("f4cfcc2").should be == ["f4cfcc2c8b1f7edb1b7817b4e8a9063d21db089b", "2fb8a3281fb6777405aadcd699adb852b615a3e4", "d7b0fa26ca547b963569d7a82afd7d7ca11b71ae", "8b38f7c842496fd50b4e1b7ca5e883940b9cbf83", "f76c8d7bf64678963aeef84009be54f1819e3389", "8299243c7dac8f27c3572424a348a7f83ef0ce28", "570fe2e6e7f0b06140ae109e50a1e86628819493", "cdd4d5aa885b22136f4a08c1b35076f888f9536e", "72174c160b50ec73a8f67c8150e0dcd976857411", "b2da007b4fb35e0274858c14a83a836852d055a4", "4f0e7e0f6b3df2d49ed0029ed01998bf2102b28f"]
13
14
  @driver.commit_history("f4cfcc2", 3).should be == ["f4cfcc2c8b1f7edb1b7817b4e8a9063d21db089b", "2fb8a3281fb6777405aadcd699adb852b615a3e4", "d7b0fa26ca547b963569d7a82afd7d7ca11b71ae"]
14
15
  end
16
+ it "should get commits between a fist commit and a last_commit" do
17
+ @driver.should respond_to :commits_between
18
+ @driver.commits_between("63c8b23", "d133b9e").should be == %w[
19
+ d133b9e3b5be37c8a3332a83e55b410e87d9c3a3
20
+ abd9ee53283de0981fd6fd659af50a2aef4fc5c6
21
+ 13de54b5cfdaf05fd4e3c3db57ec9f021362d9c7
22
+ 67931ecf42431719b5c67f88ec65cb57e7e11744
23
+ ]
24
+ @driver.commits_between("67931ec", "d133b9e").size.should be == 6
25
+ end
26
+ it "should get all remotes" do
27
+ @driver.fetched_remotes.should be == %w[origin]
28
+ end
29
+ it "should get version tag info" do
30
+ @driver.version_tag_info("v0.1.0").should be == {:message => "Features:\n\n - command line to show notes for the next version (unversioned notes)", :tagger => "Marcelo Manzan", :date => Time.parse("Thu Dec 9 02:42:14 2010 -0200")}
31
+ end
15
32
  end
16
-
17
-
18
- context 'fetching tags' do
33
+
34
+ context 'fetching all tags' do
19
35
  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]
36
+ tags = %w[note-v0.2.0-1 v0.1.0 v0.1.1 v0.1.10 v0.1.2 v0.1.1.rc3]
21
37
  @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]
38
+ @driver.all_version_tags.should be == %w[v0.1.10 v0.1.2 v0.1.1.rc3 v0.1.1 v0.1.0]
23
39
  end
24
-
40
+ end
41
+
42
+ context "fetching the last version tag" do
25
43
  it "should return last tag visible" do
26
44
  @driver.last_version_tag("f4cfcc2").should be == "v0.0.1+"
27
45
  @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
46
  end
31
-
32
- it "should get no tag visible" do
33
- @driver.last_version_tag("cdd4d5a").should be_nil
47
+
48
+ it "should get last tag visible with the count of commits after it" do
49
+ @driver.last_version_tag("f42bdd1", true).should be == "v0.0.2+22"
50
+ @driver.last_version_tag("13de54b", true).should be == "v0.0.2+22"
51
+ @driver.last_version_tag("d133b9e", true).should be == "v0.0.2+27"
34
52
  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+"
53
+
54
+ context "if there is no version tag" do
55
+ context "in the project" do
56
+ before do
57
+ @driver.stubs(:all_version_tags).returns([])
58
+ end
59
+
60
+ it "should return a blank tag" do
61
+ @driver.last_version_tag.should == "v0.0.0+"
62
+ end
63
+ end
64
+
65
+ context "in the commit history, but there is in the project" do
66
+ it "should return nil" do
67
+ @driver.last_version_tag("cdd4d5a").should be_nil
68
+ end
69
+ end
39
70
  end
40
71
  end
41
72
 
42
73
 
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
74
+ context "adding notes" do
75
+ before do
76
+ @steps = <<-STEPS
77
+ git fetch
78
+
79
+ git notes --ref=jjj_changes add -m "alteracao na variavel de ambiente \\"\\$ENV\\"" v0.1.0~1
80
+
81
+ git push origin refs/notes/jjj_changes
82
+ STEPS
83
+ @steps = @steps.rstrip.split(/\n\n/).collect{ |step| step.gsub(/^\s{6}/, '') }
84
+ end
85
+ it "should return steps" do
86
+ @driver.steps_for_add_notes("jjj_changes", "alteracao na variavel de ambiente \"$ENV\"", "v0.1.0~1").should be == @steps
86
87
  end
87
88
  end
88
89
 
89
90
 
90
91
  context "increasing version" do
91
92
  before do
92
- @driver.stubs(:notes_sections).returns(%w[test_changes test_bugfixes test_features])
93
+ notes_sections = %w[test_changes test_bugfixes test_features]
94
+ class << notes_sections
95
+ include StepUp::ConfigSectionsExt
96
+ end
97
+ StepUp::CONFIG.stubs(:notes_sections).returns(notes_sections)
98
+ StepUp::CONFIG.notes.after_versioned.stubs(:section).returns("test_versioning")
93
99
  end
94
100
 
95
101
 
96
102
  context "using 'remove' as after_versioned:strategy" do
97
103
  before do
98
- @driver.stubs(:notes_after_versioned).returns({"strategy" => "remove", "section" => "test_versioning", "changelog_message" => "available on {version}"})
104
+ StepUp::CONFIG.notes.after_versioned.stubs(:strategy).returns("remove")
99
105
  @steps = <<-STEPS
100
106
  git fetch
101
107
 
102
- git tag -a -m " - removing files from gemspec
108
+ git tag -a -m "Test changes:
109
+
110
+ - removing files from gemspec
103
111
  - .gitignore
104
112
  - lastversion.gemspec
105
113
  - loading default configuration yaml
@@ -107,8 +115,7 @@ MSG
107
115
 
108
116
  Test bugfixes:
109
117
 
110
- - sorting tags according to the mask parser
111
- " v0.1.0
118
+ - sorting tags according to the mask parser" v0.1.0
112
119
 
113
120
  git push --tags
114
121
 
@@ -122,22 +129,24 @@ MSG
122
129
 
123
130
  git push origin refs/notes/test_bugfixes
124
131
  STEPS
125
- @steps = @steps.chomp.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
132
+ @steps = @steps.rstrip.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
126
133
  end
127
134
  it "should return steps" do
128
- @driver.should respond_to :increase_version_tag
129
- @driver.increase_version_tag("minor", "f4cfcc2").should be == @steps
135
+ @driver.should respond_to :steps_to_increase_version
136
+ @driver.steps_to_increase_version("minor", "f4cfcc2").should be == @steps
130
137
  end
131
138
  end
132
139
 
133
140
 
134
141
  context "using 'keep' as after_versioned:strategy" do
135
142
  before do
136
- @driver.stubs(:notes_after_versioned).returns({"strategy" => "keep", "section" => "test_versioning", "changelog_message" => "available on {version}"})
143
+ StepUp::CONFIG.notes.after_versioned.stubs(:strategy).returns("keep")
137
144
  @steps = <<-STEPS
138
145
  git fetch
139
146
 
140
- git tag -a -m " - removing files from gemspec
147
+ git tag -a -m "Test changes:
148
+
149
+ - removing files from gemspec
141
150
  - .gitignore
142
151
  - lastversion.gemspec
143
152
  - loading default configuration yaml
@@ -145,8 +154,7 @@ MSG
145
154
 
146
155
  Test bugfixes:
147
156
 
148
- - sorting tags according to the mask parser
149
- " v0.1.0
157
+ - sorting tags according to the mask parser" v0.1.0
150
158
 
151
159
  git push --tags
152
160
 
@@ -158,11 +166,11 @@ MSG
158
166
 
159
167
  git push origin refs/notes/test_versioning
160
168
  STEPS
161
- @steps = @steps.chomp.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
169
+ @steps = @steps.rstrip.split(/\n\n/).collect{ |step| step.gsub(/^\s{8}/, '') }
162
170
  end
163
171
  it "should return steps" do
164
- @driver.should respond_to :increase_version_tag
165
- @driver.increase_version_tag("minor", "f4cfcc2").should be == @steps
172
+ @driver.should respond_to :steps_to_increase_version
173
+ @driver.steps_to_increase_version("minor", "f4cfcc2").should be == @steps
166
174
  end
167
175
  end
168
176
  end
@@ -170,7 +178,7 @@ MSG
170
178
 
171
179
  context "checking helper methods" do
172
180
  it "should load default notes' sections" do
173
- @driver.send(:notes_sections).should be == StepUp::CONFIG["notes"]["sections"]
181
+ StepUp::CONFIG.notes_sections.should be == StepUp::CONFIG["notes"]["sections"]
174
182
  end
175
183
  end
176
184
  end
@@ -6,7 +6,10 @@ describe StepUp::Parser::VersionMask do
6
6
  @mask = StepUp::Parser::VersionMask.new("v0.0.0.9.9.rc9")
7
7
  }.should_not raise_error ArgumentError
8
8
  end
9
-
9
+
10
+ it "should be able to provide a blank mask" do
11
+ @mask.blank.should be == "v0.0.0"
12
+ end
10
13
 
11
14
  context "parsing" do
12
15
  it "should parse" do
@@ -36,9 +39,9 @@ describe StepUp::Parser::VersionMask do
36
39
 
37
40
  context "increasing version" do
38
41
  before do
39
- @mask.stubs(:version_parts).returns(%w[major minor tiny patch build rc])
42
+ @mask.stubs(:version_levels).returns(%w[major minor tiny patch build rc])
40
43
  end
41
- it "should increase by parts" do
44
+ it "should increase by levels" do
42
45
  version = "v2.3.1.6.4.rc5"
43
46
  @mask.increase_version(version, "major").should be == "v3.0.0"
44
47
  @mask.increase_version(version, "minor").should be == "v2.4.0"
@@ -48,4 +51,25 @@ describe StepUp::Parser::VersionMask do
48
51
  @mask.increase_version(version, "rc").should be == "v2.3.1.6.4.rc6"
49
52
  end
50
53
  end
54
+
55
+
56
+ context "getting Regepx" do
57
+ it "should get regexp string" do
58
+ @mask.should respond_to(:to_regex)
59
+ @mask.to_regex.should be == "(?:v(\\d+))(?:\\.(\\d+))(?:\\.(\\d+))(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\.rc(\\d+))?"
60
+ end
61
+ it "should parse message" do
62
+ re = /^available on (?:#{ @mask.to_regex })$/
63
+ "available on v0.1.0".should =~ re
64
+ "available on v0.1.0.rc3".should =~ re
65
+ "available on v0.1.0.1.rc3".should =~ re
66
+ "available on v0.1.0.2.4.rc3".should =~ re
67
+ end
68
+ it "should not parse message" do
69
+ re = /^available on (?:#{ @mask.to_regex })$/
70
+ "available on v0.1".should_not =~ re
71
+ "now in v0.1.0".should_not =~ re
72
+ "available on v0.1.0 tag".should_not =~ re
73
+ end
74
+ end
51
75
  end
@@ -0,0 +1,140 @@
1
+ require "spec_helper"
2
+
3
+ describe StepUp::RangedNotes do
4
+ before do
5
+ @driver = StepUp::Driver::Git.new
6
+ end
7
+
8
+ context "checking notes" do
9
+ it "should bring all notes between v0.0.2 and v0.1.0" do
10
+ @notes = StepUp::RangedNotes.new(@driver, "v0.0.2", "v0.1.0")
11
+ @notes.all_notes.should be == [
12
+ [3, "features", 1, "3baad37d5098ad3b09935229e14e617c3ec8b7ee",
13
+ "command line to show notes for the next version (unversioned notes)\n"]
14
+ ]
15
+ end
16
+ end
17
+
18
+ context "testing notes" do
19
+ before do
20
+ notes_sections = %w[test_changes test_bugfixes test_features]
21
+ class << notes_sections
22
+ include StepUp::ConfigSectionsExt
23
+ end
24
+ StepUp::CONFIG.stubs(:notes_sections).returns(notes_sections)
25
+ StepUp::CONFIG.notes.after_versioned.stubs(:section).returns("test_versioning")
26
+ end
27
+ context "until object f4cfcc2" do
28
+ before do
29
+ @notes = StepUp::RangedNotes.new(@driver, nil, "f4cfcc2")
30
+ end
31
+ it "should get all detached notes" do
32
+ @notes.notes.should be == [
33
+ [5, "test_changes", 1, "8299243c7dac8f27c3572424a348a7f83ef0ce28",
34
+ "removing files from gemspec\n .gitignore\n lastversion.gemspec\n"],
35
+ [2, "test_bugfixes", 1, "d7b0fa26ca547b963569d7a82afd7d7ca11b71ae",
36
+ "sorting tags according to the mask parser\n"],
37
+ [1, "test_changes", 1, "2fb8a3281fb6777405aadcd699adb852b615a3e4",
38
+ "loading default configuration yaml\n\nloading external configuration yaml\n"]
39
+ ]
40
+ end
41
+ it "should get a hash of distinct notes" do
42
+ @notes.notes.should respond_to :as_hash
43
+ @notes.notes.as_hash.should be == {
44
+ "test_changes" => [
45
+ ["8299243c7dac8f27c3572424a348a7f83ef0ce28",
46
+ "removing files from gemspec\n .gitignore\n lastversion.gemspec\n", 1],
47
+ ["2fb8a3281fb6777405aadcd699adb852b615a3e4",
48
+ "loading default configuration yaml\n\nloading external configuration yaml\n", 1]
49
+ ],
50
+ "test_bugfixes" => [
51
+ ["d7b0fa26ca547b963569d7a82afd7d7ca11b71ae",
52
+ "sorting tags according to the mask parser\n", 1]
53
+ ]
54
+ }
55
+ end
56
+ it "should get the changelog message without objects" do
57
+ @notes.notes.as_hash.should respond_to :to_changelog
58
+ changelog = <<-EOF
59
+ Test changes:
60
+
61
+ - removing files from gemspec
62
+ - .gitignore
63
+ - lastversion.gemspec
64
+ - loading default configuration yaml
65
+ - loading external configuration yaml
66
+
67
+ Test bugfixes:
68
+
69
+ - sorting tags according to the mask parser
70
+ EOF
71
+ changelog.gsub!(/^\s{8}/, '')
72
+ changelog = changelog.rstrip
73
+ @notes.notes.as_hash.to_changelog.should be == changelog
74
+ end
75
+ it "should get the changelog message with objects" do
76
+ @notes.notes.as_hash.should respond_to :to_changelog
77
+ changelog = <<-EOF
78
+ Test changes:
79
+
80
+ - removing files from gemspec (8299243c7dac8f27c3572424a348a7f83ef0ce28)
81
+ - .gitignore
82
+ - lastversion.gemspec
83
+ - loading default configuration yaml (2fb8a3281fb6777405aadcd699adb852b615a3e4)
84
+ - loading external configuration yaml
85
+
86
+ Test bugfixes:
87
+
88
+ - sorting tags according to the mask parser (d7b0fa26ca547b963569d7a82afd7d7ca11b71ae)
89
+ EOF
90
+ changelog.gsub!(/^\s{8}/, '')
91
+ changelog = changelog.rstrip
92
+ @notes.notes.as_hash.to_changelog(:mode => :with_objects).should be == changelog
93
+ end
94
+ it "should get the changelog message with custom message" do
95
+ @notes.notes.as_hash.should respond_to :to_changelog
96
+ changelog = <<-EOF
97
+ Custom message:
98
+
99
+ - New version create feature
100
+ - Removed old version create feature
101
+
102
+ Test changes:
103
+
104
+ - removing files from gemspec
105
+ - .gitignore
106
+ - lastversion.gemspec
107
+ - loading default configuration yaml
108
+ - loading external configuration yaml
109
+
110
+ Test bugfixes:
111
+
112
+ - sorting tags according to the mask parser
113
+ EOF
114
+ changelog.gsub!(/^\s{8}/, '')
115
+ changelog = changelog.rstrip
116
+ message_option = {:custom_message => "New version create feature\n\nRemoved old version create feature"}
117
+ @notes.notes.as_hash.to_changelog(message_option).should be == changelog
118
+ end
119
+ it "should get the changelog message without custom message" do
120
+ @notes.notes.as_hash.should respond_to :to_changelog
121
+ changelog = <<-EOF
122
+ Test changes:
123
+
124
+ - removing files from gemspec
125
+ - .gitignore
126
+ - lastversion.gemspec
127
+ - loading default configuration yaml
128
+ - loading external configuration yaml
129
+
130
+ Test bugfixes:
131
+
132
+ - sorting tags according to the mask parser
133
+ EOF
134
+ changelog.gsub!(/^\s{8}/, '')
135
+ changelog = changelog.rstrip
136
+ @notes.notes.as_hash.to_changelog.should be == changelog
137
+ end
138
+ end
139
+ end
140
+ end