bump 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bump (0.1.3)
4
+ bump (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/bin/bump CHANGED
@@ -2,4 +2,6 @@
2
2
  require File.dirname(__FILE__) + '/../lib/bump'
3
3
 
4
4
  bump = Bump::Bump.new(ARGV)
5
- bump.run
5
+ output, status = bump.run
6
+ puts output
7
+ exit status
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new "bump" do |s|
2
- s.version = "0.1.4"
2
+ s.version = "0.1.5"
3
3
  s.author = "Gregory Marcilhacy"
4
4
  s.email = "g.marcilhacy@gmail.com"
5
5
  s.homepage = "https://github.com/gregorym/bump"
@@ -7,61 +7,53 @@ module Bump
7
7
 
8
8
  class Bump
9
9
 
10
- attr_accessor :bump, :output, :gemspec_path, :version, :next_version
10
+ attr_accessor :bump, :gemspec_path, :version, :next_version
11
11
 
12
12
  BUMPS = %w(major minor tiny)
13
13
  OPTIONS = BUMPS | ["current"]
14
- VERSION_REGEX = /version\s*=\s*["|'](\d.\d.\d)["|']/
14
+ VERSION_REGEX = /\.version\s*=\s*["'](\d+\.\d+\.\d+)["']/
15
15
 
16
16
  def initialize(bump)
17
17
  @bump = bump.is_a?(Array) ? bump.first : bump
18
18
  end
19
19
 
20
20
  def run
21
- begin
22
- raise InvalidOptionError unless OPTIONS.include?(@bump)
21
+ @version = find_current_version
23
22
 
24
- @gemspec_path = find_gemspec_file if @gemspec_path.nil?
25
- @version = find_current_version
26
-
27
- case @bump
28
- when "major", "minor", "tiny"
29
- bump
30
- when "current"
31
- current
32
- else
33
- raise Exception
34
- end
35
-
36
- rescue InvalidOptionError
37
- @output = "Invalid option. Choose between #{OPTIONS.join(',')}."
38
- rescue UnfoundVersionError
39
- @output = "Unable to find your gem version"
40
- rescue UnfoundGemspecError
41
- @output = "Unable to find gemspec file"
42
- rescue TooManyGemspecsFoundError
43
- @output = "More than one gemspec file"
44
- rescue Exception => e
45
- @output = "Something wrong happened: #{e.message}"
23
+ case @bump
24
+ when "major", "minor", "tiny"
25
+ bump
26
+ when "current"
27
+ current
28
+ else
29
+ raise InvalidOptionError
46
30
  end
47
- puts @output
48
- return @output
31
+ rescue InvalidOptionError
32
+ ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
33
+ rescue UnfoundVersionError
34
+ ["Unable to find your gem version", 1]
35
+ rescue UnfoundGemspecError
36
+ ["Unable to find gemspec file", 1]
37
+ rescue TooManyGemspecsFoundError
38
+ ["More than one gemspec file", 1]
39
+ rescue Exception => e
40
+ ["Something wrong happened: #{e.message}", 1]
49
41
  end
50
42
 
51
43
  private
52
44
 
53
45
  def bump
54
46
  @next_version = find_next_version
55
- system(%(ruby -i -pe "gsub(/#{@version}/, '#{@next_version}')" #{@gemspec_path}))
56
- @output = "Bump version #{@version} to #{@next_version}"
47
+ system(%(ruby -i -pe "gsub(/#{@version}/, '#{@next_version}')" #{gemspec_path}))
48
+ ["Bump version #{@version} to #{@next_version}", 0]
57
49
  end
58
50
 
59
51
  def current
60
- @output = "Current version: #{@version}"
52
+ ["Current version: #{@version}", 0]
61
53
  end
62
54
 
63
55
  def find_current_version
64
- match = File.read(@gemspec_path).match VERSION_REGEX
56
+ match = File.read(gemspec_path).match VERSION_REGEX
65
57
  if match.nil?
66
58
  raise UnfoundVersionError
67
59
  else
@@ -69,24 +61,26 @@ module Bump
69
61
  end
70
62
  end
71
63
 
72
- def find_gemspec_file
73
- gemspecs = Dir.glob("*.gemspec")
74
- raise UnfoundGemspecError if gemspecs.size.zero?
75
- raise TooManyGemspecsFoundError if gemspecs.size > 1
76
- gemspecs.first
64
+ def gemspec_path
65
+ @gemspec_path ||= begin
66
+ gemspecs = Dir.glob("*.gemspec")
67
+ raise UnfoundGemspecError if gemspecs.size.zero?
68
+ raise TooManyGemspecsFoundError if gemspecs.size > 1
69
+ gemspecs.first
70
+ end
77
71
  end
78
72
 
79
73
  def find_next_version
80
- match = @version.match /(\d).(\d).(\d)/
74
+ match = @version.match /(\d+)\.(\d+)\.(\d+)/
81
75
  case @bump
82
- when "major"
83
- "#{match[1].to_i + 1}.0.0"
84
- when "minor"
85
- "#{match[1]}.#{match[2].to_i + 1}.0"
86
- when "tiny"
87
- "#{match[1]}.#{match[2]}.#{match[3].to_i + 1}"
76
+ when "major"
77
+ "#{match[1].to_i + 1}.0.0"
78
+ when "minor"
79
+ "#{match[1]}.#{match[2].to_i + 1}.0"
80
+ when "tiny"
81
+ "#{match[1]}.#{match[2]}.#{match[3].to_i + 1}"
88
82
  end
89
- end
83
+ end
90
84
 
91
85
  end
92
86
  end
@@ -1,45 +1,101 @@
1
1
  require File.dirname(__FILE__) + "/../lib/bump.rb"
2
2
 
3
3
  describe Bump do
4
+ let(:gemspec){ "fixture.gemspec" }
4
5
 
5
6
  around do |example|
6
- gemspec = <<-RUBY.sub(" "*6, "")
7
- Gem::Specification.new do |s|
8
- s.version = "1.0.0"
9
- end
10
- RUBY
11
- path = File.expand_path("../fixture/fixture.gemspec", __FILE__)
12
- File.open(path, 'w') {|f| f.write(gemspec) }
13
- example.call
14
- File.open(path, 'w') {|f| f.write("") }
7
+ run "rm -rf fixture && mkdir fixture"
8
+ Dir.chdir "fixture" do
9
+ example.call
10
+ end
11
+ run "rm -rf fixture"
15
12
  end
16
13
 
17
- it "should find current version" do
18
- bump = Bump::Bump.new("current")
19
- bump.gemspec_path = File.dirname(__FILE__) + "/fixture/fixture.gemspec"
20
- output = bump.run
21
- output.include?("1.0.0").should be_true
14
+ it "should fail if it cannot find anything to bump" do
15
+ bump("current", :fail => true).should include "Unable to find"
22
16
  end
23
17
 
24
- it "should bump a tiny version" do
25
- bump = Bump::Bump.new("tiny")
26
- bump.gemspec_path = File.dirname(__FILE__) + "/fixture/fixture.gemspec"
27
- output = bump.run
28
- output.include?("1.0.1").should be_true
18
+ it "should fail without command" do
19
+ write_gemspec
20
+ bump("", :fail => true).should include "Invalid option"
29
21
  end
30
-
31
- it "should bump a minor version" do
32
- bump = Bump::Bump.new("minor")
33
- bump.gemspec_path = File.dirname(__FILE__) + "/fixture/fixture.gemspec"
34
- output = bump.run
35
- output.include?("1.1.0").should be_true
22
+
23
+ it "should fail with multiple gemspecs" do
24
+ write_gemspec
25
+ write("xxxx.gemspec", "xxx")
26
+ bump("", :fail => true).should include "More than one gemspec file"
36
27
  end
37
-
38
- it "should bump a major version" do
39
- bump = Bump::Bump.new("major")
40
- bump.gemspec_path = File.dirname(__FILE__) + "/fixture/fixture.gemspec"
41
- output = bump.run
42
- output.include?("2.0.0").should be_true
28
+
29
+ it "should fail if version is weird" do
30
+ write_gemspec("a.b.c")
31
+ bump("", :fail => true).should include "Unable to find your gem version"
43
32
  end
44
33
 
34
+ context ".version in gemspect" do
35
+ before do
36
+ write_gemspec
37
+ end
38
+
39
+ it "should find current version" do
40
+ bump("current").should include("4.2.3")
41
+ read(gemspec).should include('s.version = "4.2.3"')
42
+ end
43
+
44
+ it "should bump tiny" do
45
+ bump("tiny").should include("4.2.4")
46
+ read(gemspec).should include('s.version = "4.2.4"')
47
+ end
48
+
49
+ it "should bump minor" do
50
+ bump("minor").should include("4.3.0")
51
+ read(gemspec).should include('s.version = "4.3.0"')
52
+ end
53
+
54
+ it "should bump major" do
55
+ bump("major").should include("5.0.0")
56
+ read(gemspec).should include('s.version = "5.0.0"')
57
+ end
58
+
59
+ it "should bump more then 10" do
60
+ bump("tiny").should include("4.2.4")
61
+ bump("tiny").should include("4.2.5")
62
+ bump("tiny").should include("4.2.6")
63
+ bump("tiny").should include("4.2.7")
64
+ bump("tiny").should include("4.2.8")
65
+ bump("tiny").should include("4.2.9")
66
+ bump("tiny").should include("4.2.10")
67
+ bump("tiny").should include("4.2.11")
68
+ read(gemspec).should include('s.version = "4.2.11"')
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def write(file, content)
75
+ folder = File.dirname(file)
76
+ run "mkdir -p #{folder}" unless File.exist?(folder)
77
+ File.open(file, 'w'){|f| f.write content }
78
+ end
79
+
80
+ def read(file)
81
+ File.read(file)
82
+ end
83
+
84
+ def run(cmd, options={})
85
+ result = `#{cmd} 2>&1`
86
+ raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
87
+ result
88
+ end
89
+
90
+ def bump(command="", options={})
91
+ run "#{File.expand_path("../../bin/bump", __FILE__)} #{command}", options
92
+ end
93
+
94
+ def write_gemspec(version = "4.2.3")
95
+ write gemspec, <<-RUBY.sub(" "*6, "")
96
+ Gem::Specification.new do |s|
97
+ s.version = "#{version}"
98
+ end
99
+ RUBY
100
+ end
45
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: g.marcilhacy@gmail.com