bmp 1.2.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,30 +1,22 @@
1
-
2
-
3
1
  module Bump
4
-
5
- # The factory class for the file update rule model
6
- class FileUpdateRuleFactory
7
-
8
- # Creates the file update rule from the given params.
9
- #
10
- # @param [String] file The filename
11
- # @param [String|Array] param The version update info
12
- # @param [String] before_version
13
- # @param [String] after_version
14
- # @return [Bump::FileUpdateRule, Array<Bump::FileUpdateRule>]
15
- def self.create file, param, before_version, after_version
16
-
17
- case param
18
- when String
19
- return FileUpdateRule.new file, param, before_version, after_version
20
- when Array
21
- return param.map { |param| FileUpdateRule.new file, param, before_version, after_version }.flatten
22
- else
23
- return FileUpdateRule.new file, nil, before_version, after_version
24
- end
25
-
26
- end
27
-
2
+ # The factory class for the file update rule model
3
+ class FileUpdateRuleFactory
4
+ # Creates the file update rule from the given params.
5
+ #
6
+ # @param [String] file The filename
7
+ # @param [String|Array] param The version update info
8
+ # @param [String] before_version
9
+ # @param [String] after_version
10
+ # @return [Bump::FileUpdateRule, Array<Bump::FileUpdateRule>]
11
+ def self.create(file, param, before_version, after_version)
12
+ case param
13
+ when String
14
+ return FileUpdateRule.new file, param, before_version, after_version
15
+ when Array
16
+ return param.map { |param0| FileUpdateRule.new file, param0, before_version, after_version }.flatten
17
+ else
18
+ return FileUpdateRule.new file, nil, before_version, after_version
19
+ end
28
20
  end
29
-
21
+ end
30
22
  end
@@ -1,63 +1,46 @@
1
- # lib/bump/domain/version.rb
2
-
3
1
  module Bump
2
+ # The version number model
3
+ class VersionNumber
4
+ attr_writer :preid
5
+
6
+ # @param [Integer] major
7
+ # @param [Integer] minor
8
+ # @param [Integer] patch
9
+ # @param [String, nil] preid
10
+ def initialize(major, minor, patch, preid = nil)
11
+ @major = major
12
+ @minor = minor
13
+ @patch = patch
14
+ @preid = preid
15
+ end
4
16
 
5
- # The version number model
6
- class VersionNumber
7
-
8
- # @param [Integer] major
9
- # @param [Integer] minor
10
- # @param [Integer] patch
11
- # @param [String, nil] preid
12
- def initialize major, minor, patch, preid = nil
13
- @major = major
14
- @minor = minor
15
- @patch = patch
16
- @preid = preid
17
- end
18
-
19
- # Bumps the version at the given level
20
- #
21
- # @param [Symbol] level
22
- # @return [void]
23
- def bump level
24
-
25
- case level
26
- when :major
27
- @major += 1
28
- @minor = 0
29
- @patch = 0
30
- when :minor
31
- @minor += 1
32
- @patch = 0
33
- when :patch
34
- @patch += 1
35
- end
36
- @preid = nil
37
-
38
- end
39
-
40
- # Sets the preid
41
- #
42
- # @return [void]
43
- def setPreid preid
44
- @preid = preid
45
- end
46
-
47
- # Returns the string representation of the version
48
- #
49
- # @return [String]
50
- def to_s
51
- label = @major.to_s + '.' + @minor.to_s + '.' + @patch.to_s
52
-
53
- if @preid
54
- label = label + '-' + @preid
55
- end
17
+ # Bumps the version at the given level
18
+ #
19
+ # @param [Symbol] level
20
+ # @return [void]
21
+ def bump(level)
22
+ case level
23
+ when :major
24
+ @major += 1
25
+ @minor = 0
26
+ @patch = 0
27
+ when :minor
28
+ @minor += 1
29
+ @patch = 0
30
+ when :patch
31
+ @patch += 1
32
+ end
33
+ @preid = nil
34
+ end
56
35
 
57
- label
36
+ # Returns the string representation of the version
37
+ # @return [String]
38
+ def to_s
39
+ label = @major.to_s + '.' + @minor.to_s + '.' + @patch.to_s
58
40
 
59
- end
41
+ label = label + '-' + @preid if @preid
60
42
 
43
+ label
61
44
  end
62
-
45
+ end
63
46
  end
@@ -1,23 +1,17 @@
1
-
2
-
3
1
  module Bump
4
-
5
- # The factory class for the version number
6
- class VersionNumberFactory
7
-
8
- # Regexp for version expression
9
- VERSION_REGEXP = /^(\d+).(\d+).(\d+)(-(\S*))?$/
10
-
11
- # Creates the version number object from the string
12
- #
13
- # @param [String] version_string
14
- # @return [Bump::VersionNumber]
15
- def self.fromString version_string
16
- match = VERSION_REGEXP.match version_string
17
-
18
- return VersionNumber.new match[1].to_i, match[2].to_i, match[3].to_i, match[5]
19
- end
20
-
2
+ # The factory class for the version number
3
+ class VersionNumberFactory
4
+ # Regexp for version expression
5
+ VERSION_REGEXP = /^(\d+).(\d+).(\d+)(-(\S*))?$/
6
+
7
+ # Creates the version number object from the string
8
+ #
9
+ # @param [String] version_string
10
+ # @return [Bump::VersionNumber]
11
+ def self.from_string(version_string)
12
+ match = VERSION_REGEXP.match version_string
13
+
14
+ VersionNumber.new match[1].to_i, match[2].to_i, match[3].to_i, match[5]
21
15
  end
22
-
16
+ end
23
17
  end
@@ -1,54 +1,48 @@
1
- # lib/bump/logger.rb
2
-
3
1
  module Bump
2
+ # The logging class
3
+ class Logger
4
+ def initialize(no_color = nil)
5
+ @no_color = no_color
6
+ end
4
7
 
5
- # The logging class
6
- class Logger
7
-
8
- no_color = false
9
-
10
- # Logs the message.
11
- #
12
- # @param [String] message
13
- # @param [Boolean] breakline
14
- # @return [void]
15
- def log message = '', breakline = true
16
- print message
17
-
18
- if breakline
19
- print "\n"
20
- end
21
- end
22
-
23
- # Colorize the text by the color code.
24
- #
25
- # @param [String] text
26
- # @param [Integer] color_code
27
- # @return [String]
28
- def colorize text, color_code
29
- if @no_color
30
- text
31
- else
32
- "\e[#{color_code}m#{text}\e[0m"
33
- end
34
- end
8
+ # Logs the message.
9
+ #
10
+ # @param [String] message
11
+ # @param [Boolean] breakline
12
+ # @return [void]
13
+ def log(message = '', breakline = true)
14
+ print message
35
15
 
36
- # Returns a green string.
37
- #
38
- # @param [String] text
39
- # @return [String]
40
- def green text
41
- colorize text, 32
42
- end
16
+ print "\n" if breakline
17
+ end
43
18
 
44
- # Returns a red string.
45
- #
46
- # @param [String] text
47
- # @return [String]
48
- def red text
49
- colorize text, 31
50
- end
19
+ # Colorize the text by the color code.
20
+ #
21
+ # @param [String] text
22
+ # @param [Integer] color_code
23
+ # @return [String]
24
+ def colorize(text, color_code)
25
+ if @no_color
26
+ text
27
+ else
28
+ "\e[#{color_code}m#{text}\e[0m"
29
+ end
30
+ end
51
31
 
32
+ # Returns a green string.
33
+ #
34
+ # @param [String] text
35
+ # @return [String]
36
+ def green(text)
37
+ colorize text, 32
52
38
  end
53
39
 
40
+ # Returns a red string.
41
+ #
42
+ # @param [String] text
43
+ # @return [String]
44
+ def red(text)
45
+ colorize text, 31
46
+ end
47
+ end
54
48
  end
@@ -1,4 +1,3 @@
1
1
  module Bump
2
- # The version
3
- VERSION = "1.2.0"
2
+ VERSION = '1.3.1'.freeze
4
3
  end
@@ -3,70 +3,153 @@ require 'spec_helper'
3
3
  require 'bump'
4
4
 
5
5
  describe Bump::Application do
6
+ before :each do
7
+ @help_message = 'help_message'
8
+ @version_exp = "Bmp #{Bump::VERSION}"
9
+ @bmp_file = 'spec/fixture/bmp.yml'
10
+
11
+ @logger = double 'logger'
12
+ allow(@logger).to receive(:log)
13
+ allow(@logger).to receive(:green)
14
+ allow(@logger).to receive(:red)
15
+ end
16
+
17
+ describe '#select_action' do
18
+ it 'returns :help if the options contain :help' do
19
+ app = Bump::Application.new({ help: true }, @help_message, @version_exp, @bmp_file, @logger)
20
+
21
+ expect(app.select_action).to eq :help
22
+ end
23
+
24
+ it 'returns :version if the :version option preset' do
25
+ app = Bump::Application.new({ version: true }, @help_message, @version_exp, @bmp_file, @logger)
26
+
27
+ expect(app.select_action).to eq :version
28
+ end
29
+
30
+ it 'returns :info if the :info option present' do
31
+ app = Bump::Application.new({ info: true }, @help_message, @version_exp, @bmp_file, @logger)
32
+
33
+ expect(app.select_action).to eq :info
34
+ end
6
35
 
7
- before :each do
8
- @help_message = 'help_message'
9
- @version_exp = "Bmp #{Bump::VERSION}"
10
- @bmp_file = 'spec/fixture/bmp.yml'
11
- @logger = Bump::Logger.new
36
+ it 'returns :bump if one of :major, :minor, :patch, :commit, :preid, :release options present' do
37
+ app = Bump::Application.new({ major: true }, @help_message, @version_exp, @bmp_file, @logger)
38
+ expect(app.select_action).to eq :bump
39
+
40
+ app = Bump::Application.new({ minor: true }, @help_message, @version_exp, @bmp_file, @logger)
41
+ expect(app.select_action).to eq :bump
42
+
43
+ app = Bump::Application.new({ patch: true }, @help_message, @version_exp, @bmp_file, @logger)
44
+ expect(app.select_action).to eq :bump
45
+
46
+ app = Bump::Application.new({ commit: true }, @help_message, @version_exp, @bmp_file, @logger)
47
+ expect(app.select_action).to eq :bump
48
+
49
+ app = Bump::Application.new({ preid: true }, @help_message, @version_exp, @bmp_file, @logger)
50
+ expect(app.select_action).to eq :bump
51
+
52
+ app = Bump::Application.new({ release: true }, @help_message, @version_exp, @bmp_file, @logger)
53
+ expect(app.select_action).to eq :bump
54
+ end
12
55
 
56
+ it 'returns :info if none of the above options are present' do
57
+ app = Bump::Application.new({}, @help_message, @version_exp, @bmp_file, @logger)
58
+ expect(app.select_action).to eq :info
13
59
  end
60
+ end
14
61
 
15
- describe 'selectAction' do
62
+ describe '#main' do
63
+ it 'logs version and returns true when the version option is given' do
64
+ expect(@logger).to receive(:log).with("Bmp #{Bump::VERSION}", true).once
16
65
 
17
- it 'returns :help if the options contain :help' do
66
+ app = Bump::Application.new({ version: true }, @help_message, @version_exp, @bmp_file, @logger)
67
+ expect(app.main).to be true
68
+ end
18
69
 
19
- app = Bump::Application.new({ :help => true }, @help_message, @version_exp, @bmp_file, @logger)
70
+ it 'logs help message and returns true when the help option is given' do
71
+ expect(@logger).to receive(:log).with('help_message', true).once
20
72
 
21
- expect(app.selectAction).to eq :help
73
+ app = Bump::Application.new({ help: true }, @help_message, @version_exp, @bmp_file, @logger)
74
+ expect(app.main).to be true
75
+ end
22
76
 
23
- end
77
+ it 'shows bump info and return true when there is no error' do
78
+ app = Bump::Application.new({ info: true }, @help_message, @version_exp, @bmp_file, @logger)
24
79
 
25
- it 'returns :version if the :version option preset' do
80
+ expect(app.main).to be true
81
+ end
26
82
 
27
- app = Bump::Application.new({ :version => true }, @help_message, @version_exp, @bmp_file, @logger)
83
+ it 'shows bump info and returns false when there are errors' do
84
+ app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid.yml', @logger)
28
85
 
29
- expect(app.selectAction).to eq :version
86
+ expect(app.main).to be false
87
+ end
30
88
 
31
- end
89
+ it 'returns false when the pattern in bmp.yml is invalid' do
90
+ app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
32
91
 
33
- it 'returns :info if the :info option present' do
92
+ expect(app.main).to be false
93
+ end
94
+
95
+ it 'returns false when the bmp.yml not found' do
96
+ app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_not_exists.yml', @logger)
34
97
 
35
- app = Bump::Application.new({ :info => true }, @help_message, @version_exp, @bmp_file, @logger)
98
+ expect(app.main).to be false
99
+ end
36
100
 
37
- expect(app.selectAction).to eq :info
101
+ describe 'with :major|:minor|:patch|:preid|:release options' do
102
+ it 'returns false when the pattern in bmp.yml is invalid' do
103
+ app = Bump::Application.new({ major: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
38
104
 
39
- end
105
+ expect(app.main).to be false
40
106
 
41
- it 'returns :bump if one of :major, :minor, :patch, :commit, :preid, :release options present' do
107
+ app = Bump::Application.new({ minor: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
42
108
 
43
- app = Bump::Application.new({ :major => true }, @help_message, @version_exp, @bmp_file, @logger)
44
- expect(app.selectAction).to eq :bump
109
+ expect(app.main).to be false
45
110
 
46
- app = Bump::Application.new({ :minor => true }, @help_message, @version_exp, @bmp_file, @logger)
47
- expect(app.selectAction).to eq :bump
111
+ app = Bump::Application.new({ patch: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
48
112
 
49
- app = Bump::Application.new({ :patch => true }, @help_message, @version_exp, @bmp_file, @logger)
50
- expect(app.selectAction).to eq :bump
113
+ expect(app.main).to be false
51
114
 
52
- app = Bump::Application.new({ :commit => true }, @help_message, @version_exp, @bmp_file, @logger)
53
- expect(app.selectAction).to eq :bump
115
+ app = Bump::Application.new({ preid: 'beta.1' }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
54
116
 
55
- app = Bump::Application.new({ :preid => true }, @help_message, @version_exp, @bmp_file, @logger)
56
- expect(app.selectAction).to eq :bump
117
+ expect(app.main).to be false
57
118
 
58
- app = Bump::Application.new({ :release => true }, @help_message, @version_exp, @bmp_file, @logger)
59
- expect(app.selectAction).to eq :bump
119
+ app = Bump::Application.new({ release: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
60
120
 
61
- end
121
+ expect(app.main).to be false
122
+ end
62
123
 
63
- it 'returns :info if none of the above options are present' do
124
+ it 'returns true when no error found' do
125
+ File.write 'spec/fixture/tmp_bmp_tmp.yml', File.read('spec/fixture/bmp_tmp.yml', encoding: Encoding::UTF_8)
126
+ File.write 'spec/fixture/tmp_dummy.txt', File.read('spec/fixture/dummy.txt', encoding: Encoding::UTF_8)
64
127
 
65
- app = Bump::Application.new({}, @help_message, @version_exp, @bmp_file, @logger)
66
- expect(app.selectAction).to eq :info
128
+ app = Bump::Application.new({ patch: true }, @help_message, @version_exp, 'spec/fixture/tmp_bmp_tmp.yml', @logger)
67
129
 
68
- end
130
+ expect(app.main).to be true
69
131
 
132
+ File.delete 'spec/fixture/tmp_bmp_tmp.yml'
133
+ File.delete 'spec/fixture/tmp_dummy.txt'
134
+ end
70
135
  end
71
136
 
137
+ describe 'with :commit options' do
138
+ it 'executes git commands if there is no error' do
139
+ File.write 'spec/fixture/tmp_bmp_tmp.yml', File.read('spec/fixture/bmp_tmp.yml', encoding: Encoding::UTF_8)
140
+ File.write 'spec/fixture/tmp_dummy.txt', File.read('spec/fixture/dummy.txt', encoding: Encoding::UTF_8)
141
+
142
+ command = double 'command'
143
+
144
+ app = Bump::Application.new({ patch: true, commit: true }, @help_message, @version_exp, 'spec/fixture/tmp_bmp_tmp.yml', @logger, command)
145
+
146
+ expect(command).to receive(:exec).thrice
147
+
148
+ expect(app.main).to be true
149
+
150
+ File.delete 'spec/fixture/tmp_bmp_tmp.yml'
151
+ File.delete 'spec/fixture/tmp_dummy.txt'
152
+ end
153
+ end
154
+ end
72
155
  end