bummr 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb83d2ce7db59a0420fbfb78ca04026aafa4c945
4
- data.tar.gz: 6f4a32d78dabf543fc17469e939419ab10e9f091
3
+ metadata.gz: a6413e280f39b5c4f19afd9bffd18b6b86c324a1
4
+ data.tar.gz: 292d5f9cbbd1a73c93e12012acb8008078024484
5
5
  SHA512:
6
- metadata.gz: 309abf056757d64abdc38fe77a373c8575d9607e582620246a53fa0ad42f45b5103239ae3f589d64e7303ab0119bc27058eb6a162516b7c8c7d8bc28c8842e61
7
- data.tar.gz: 50f5c6b7b537e4271cc7c3ca4672b41db8a48e190e8ae8f8492c3393052b483a5c450d52afb433a85a10851258b27e49e8f2979aeeb4a5f8a164f69e36b226fa
6
+ metadata.gz: 9192c684fd46c2b0ea404d9e837dccd708d4c5f804edcd3583046d3d58e0e173945ed58f990e650eca95bc92cef959df476e9e86d396d6289014f056b30dceef
7
+ data.tar.gz: 586e248bebae4861de260e63cc98f0fbd53d381ad267d0974913b4ff967a3cd4e5a60c4fb3cd5fad5c33c511ebaefb792cffc03dd9ff3c19eb275aa241a84823
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Bummr
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/lpender/bummr.svg?style=svg)](https://circleci.com/gh/lpender/bummr)
4
+ [![Code Climate](https://codeclimate.com/github/lpender/bummr/badges/gpa.svg)](https://codeclimate.com/github/lpender/bummr)
5
+ [![Test Coverage](https://codeclimate.com/github/lpender/bummr/badges/coverage.svg)](https://codeclimate.com/github/lpender/bummr/coverage)
6
+
3
7
  Updating Gems one by one is a bumm(e)r: especially when one gem causes your build
4
8
  to fail.
5
9
 
@@ -94,13 +98,6 @@ I'd like to create feature tests, but because Bummr relies on command line
94
98
  manipulations which need to be doubled, I'm waiting on [this
95
99
  issue](https://github.com/bjoernalbers/aruba-doubles/issues/5)
96
100
 
97
- ## Wanted
98
-
99
- Here are some things I'd love to add to Bummr:
100
-
101
- - Test coverage.
102
- - Configuration options (for test script path, name of master branch, etc)
103
-
104
101
  ## Thank you!
105
102
 
106
103
  Thanks to Ryan Sonnek for the [Bundler
data/bummr.gemspec CHANGED
@@ -23,10 +23,12 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "rspec"
25
25
  spec.add_development_dependency "rspec-nc"
26
+ spec.add_development_dependency "spring"
26
27
  spec.add_development_dependency "bundler"
27
28
  spec.add_development_dependency "rake"
28
29
  spec.add_development_dependency "guard"
29
30
  spec.add_development_dependency "pry"
30
31
  spec.add_development_dependency "pry-remote"
31
32
  spec.add_development_dependency "pry-nav"
33
+ spec.add_development_dependency "codeclimate-test-reporter"
32
34
  end
@@ -0,0 +1,29 @@
1
+ module Bummr
2
+ class Bisecter
3
+ include Singleton
4
+
5
+ def bisect
6
+ puts "Bad commits found! Bisecting...".red
7
+
8
+ system("bundle")
9
+ system("git bisect start")
10
+ system("git bisect bad")
11
+ system("git bisect good master")
12
+
13
+ Open3.popen2e("git bisect run #{TEST_COMMAND}") do |_std_in, std_out_err|
14
+ while line = std_out_err.gets
15
+ puts line
16
+
17
+ sha_regex = Regexp::new("(.*) is the first bad commit\n").match(line)
18
+ unless sha_regex.nil?
19
+ sha = sha_regex[1]
20
+ end
21
+
22
+ if line == "bisect run success\n"
23
+ Bummr::Rebaser.instance.remove_commit(sha)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,70 @@
1
+ module Bummr
2
+ class Check
3
+ include Singleton
4
+
5
+ def check(fullcheck=true)
6
+ @errors = []
7
+
8
+ check_master
9
+ check_log
10
+ check_status
11
+
12
+ if fullcheck == true
13
+ check_diff
14
+ end
15
+
16
+ if @errors.any?
17
+ unless yes? "Bummr found errors! Do you want to continue anyway?".red
18
+ exit 0
19
+ end
20
+ else
21
+ puts "Ready to run bummr.".green
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def check_master
28
+ if `git rev-parse --abbrev-ref HEAD` == "master\n"
29
+ message = "Bummr is not meant to be run on master"
30
+ puts message.red
31
+ puts "Please checkout a branch with 'git checkout -b update-gems'"
32
+ @errors.push message
33
+ end
34
+ end
35
+
36
+ def check_log
37
+ unless File.directory? "log"
38
+ message = "There is no log directory or you are not in the root"
39
+ puts message.red
40
+ @errors.push message
41
+ end
42
+ end
43
+
44
+ def check_status
45
+ status = `git status`
46
+
47
+ if status.index 'are currently'
48
+ message = ""
49
+
50
+ if status.index 'rebasing'
51
+ message += "You are already rebasing. "
52
+ elsif status.index 'bisecting'
53
+ message += "You are already bisecting. "
54
+ end
55
+
56
+ message += "Make sure `git status` is clean"
57
+ puts message.red
58
+ @errors.push message
59
+ end
60
+ end
61
+
62
+ def check_diff
63
+ unless `git diff master`.empty?
64
+ message = "Please make sure that `git diff master` returns empty"
65
+ puts message.red
66
+ @errors.push message
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/bummr/cli.rb CHANGED
@@ -1,125 +1,49 @@
1
- require 'thor'
2
- require 'open3'
3
- require 'colorize'
4
-
5
1
  TEST_COMMAND = ENV["BUMMR_TEST"] || "bundle exec rake"
6
2
 
7
3
  module Bummr
8
4
  class CLI < Thor
5
+ include Bummr::Log
6
+
9
7
  desc "check", "Run automated checks to see if bummr can be run"
10
8
  def check(fullcheck=true)
11
- errors = []
12
-
13
- if `git rev-parse --abbrev-ref HEAD` == "master\n"
14
- message = "Bummr is not meant to be run on master"
15
- say message.red
16
- say "Please checkout a branch with 'git checkout -b update-gems'"
17
- errors.push message
18
- end
19
-
20
- unless File.directory? "log"
21
- message = "There is no log directory or you are not in the root"
22
- say message.red
23
- errors.push message
24
- end
25
-
26
- status = `git status`
27
-
28
- if status.index 'are currently'
29
- message = ""
30
-
31
- if status.index 'rebasing'
32
- message += "You are already rebasing. "
33
- elsif status.index 'bisecting'
34
- message += "You are already bisecting. "
35
- end
36
-
37
- message += "Make sure `git status` is clean"
38
- say message.red
39
- errors.push message
40
- end
41
-
42
- if fullcheck == true
43
- unless `git diff master`.empty?
44
- message = "Please make sure that `git diff master` returns empty"
45
- say message.red
46
- errors.push message
47
- end
48
- end
49
-
50
- if errors.any?
51
- exit 0
52
- else
53
- puts "Ready to run bummr.".green
54
-
55
- end
9
+ Bummr::Check.instance.check(fullcheck)
56
10
  end
57
11
 
58
12
  desc "update", "Update outdated gems, run tests, bisect if tests fail"
59
13
  def update
60
- say "To run Bummr, you must:"
61
- say "- Be in the root path of a clean git branch off of master"
62
- say "- Have no commits or local changes"
63
- say "- Have a 'log' directory, where we can place logs"
64
- say "- Have your build configured to fail fast (recommended)"
65
- say "- Have locked any Gem version that you don't wish to update in your Gemfile"
66
- say "- It is recommended that you lock your versions of `ruby` and `rails in your Gemfile`"
67
- say "Your test command is: '#{TEST_COMMAND}'"
14
+ ask_questions
68
15
 
69
16
  if yes? "Are you ready to use Bummr? (y/n)"
70
17
  check
71
18
  log("Bummr update initiated #{Time.now}")
72
- `bundle`
19
+ system("bundle")
73
20
 
74
21
  outdated_gems = Bummr::Outdated.instance.outdated_gems
75
22
 
76
23
  if outdated_gems.empty?
77
- say "No outdated gems to update".green
24
+ puts "No outdated gems to update".green
78
25
  else
79
- say "Updating outdated gems".green
26
+ Bummr::Updater.new(outdated_gems).update_gems
80
27
 
81
- outdated_gems.each_with_index do |gem, index|
82
- say "Updating #{gem[:name]}: #{index+1} of #{outdated_gems.count}"
83
-
84
- system("bundle update --source #{gem[:name]}")
85
- updated_version = `bundle list | grep " #{gem[:name]} "`.split('(')[1].split(')')[0]
86
- message = "Update #{gem[:name]} from #{gem[:installed]} to #{updated_version}"
87
-
88
- if gem[:newest] != updated_version
89
- log("#{gem[:name]} not updated from #{gem[:installed]} to latest: #{gem[:newest]}")
90
- end
91
-
92
- unless gem[:installed] == updated_version
93
- say message.green
94
- system("git commit -am '#{message}'")
95
- else
96
- log("#{gem[:name]} not updated")
97
- end
98
- end
99
-
100
- say "Choose which gems to update"
101
28
  system("git rebase -i master")
102
-
103
- log "Running Update + #{Time.now}"
104
-
105
29
  test
106
30
  end
107
31
  else
108
- say "Thank you!".green
32
+ puts "Thank you!".green
109
33
  end
110
34
  end
111
35
 
112
36
  desc "test", "Test for a successful build and bisect if necesssary"
113
37
  def test
114
38
  check(false)
115
- `bundle`
116
- say "Testing the build!".green
39
+ system "bundle"
40
+ puts "Testing the build!".green
117
41
 
118
42
  if system(TEST_COMMAND) == false
119
43
  bisect
120
44
  else
121
- say "Passed the build!".green
122
- say "See log/bummr.log for details".yellow
45
+ puts "Passed the build!".green
46
+ puts "See log/bummr.log for details".yellow
123
47
  system("cat log/bummr.log")
124
48
  end
125
49
  end
@@ -127,54 +51,21 @@ module Bummr
127
51
  desc "bisect", "Find the bad commit, remove it, test again"
128
52
  def bisect
129
53
  check(false)
130
- say "Bad commits found! Bisecting...".red
131
-
132
- system("git bisect start head master")
133
-
134
- Open3.popen2e("git bisect run #{TEST_COMMAND}") do |std_in, std_out_err|
135
- while line = std_out_err.gets
136
- puts line
137
-
138
- sha_regex = Regexp::new("(.*) is the first bad commit\n").match(line)
139
- unless sha_regex.nil?
140
- sha = sha_regex[1]
141
- end
142
54
 
143
- if line == "bisect run success\n"
144
- remove_commit(sha)
145
- end
146
- end
147
- end
55
+ Bummr::Bisecter.instance.bisect
148
56
  end
149
57
 
150
58
  private
151
59
 
152
- def log(message)
153
- say message
154
- system("touch log/bummr.log && echo '#{message}' >> log/bummr.log")
155
- end
156
-
157
- def remove_commit(sha)
158
- commit_message = `git log --pretty=format:'%s' -n 1 #{sha}`
159
- message = "Could not apply: #{commit_message}, #{sha}"
160
-
161
- say message.red
162
- log message
163
-
164
- say "Resetting..."
165
- system("git bisect reset")
166
-
167
- say "Removing commit..."
168
- if system("git rebase -X ours --onto #{sha}^ #{sha}")
169
- say "Successfully removed bad commit...".green
170
- say "Re-testing build...".green
171
- test
172
- else
173
- say message.red
174
- say "Could not automatically remove this commit!".red
175
- say "Please resolve conflicts, then 'git rebase --continue'."
176
- say "Run 'bummr test' again once the rebase is complete"
177
- end
60
+ def ask_questions
61
+ puts "To run Bummr, you must:"
62
+ puts "- Be in the root path of a clean git branch off of master"
63
+ puts "- Have no commits or local changes"
64
+ puts "- Have a 'log' directory, where we can place logs"
65
+ puts "- Have your build configured to fail fast (recommended)"
66
+ puts "- Have locked any Gem version that you don't wish to update in your Gemfile"
67
+ puts "- It is recommended that you lock your versions of `ruby` and `rails in your Gemfile`"
68
+ puts "Your test command is: '#{TEST_COMMAND}'"
178
69
  end
179
70
  end
180
71
  end
data/lib/bummr/log.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Bummr
2
+ module Log
3
+ def log(message)
4
+ puts message
5
+ system("touch log/bummr.log && echo '#{message}' >> log/bummr.log")
6
+ end
7
+ end
8
+ end
@@ -9,7 +9,7 @@ module Bummr
9
9
  @outdated_gems ||= begin
10
10
  results = []
11
11
 
12
- Open3.popen2("bundle outdated --strict") do |std_in, std_out|
12
+ Open3.popen2("bundle outdated --strict") do |_std_in, std_out|
13
13
  while line = std_out.gets
14
14
  puts line
15
15
  gem = parse_gem_from(line)
@@ -25,13 +25,15 @@ module Bummr
25
25
  end
26
26
 
27
27
  def parse_gem_from(line)
28
- regex = / \* (.*) \(newest (\d.*\d), installed (\d.*\d)[\),\s]/.match line
28
+ regex = / \* (.*) \(newest (\d[\d\.]*\d)[,\s] installed (\d[\d\.]*\d)[\),\s]/.match line
29
29
 
30
30
  unless regex.nil?
31
31
  { name: regex[1], newest: regex[2], installed: regex[3] }
32
32
  end
33
33
  end
34
34
 
35
+ private
36
+
35
37
  def gemfile_contains(gem_name)
36
38
  /gem ['"]#{gem_name}['"]/.match gemfile
37
39
  end
@@ -0,0 +1,29 @@
1
+ module Bummr
2
+ class Rebaser
3
+ include Singleton
4
+ include Log
5
+
6
+ def remove_commit(sha)
7
+ log "Bad commit: #{commit_message_for(sha)}, #{sha}".red
8
+ log "Resetting..."
9
+ system("git bisect reset")
10
+
11
+ log "Removing commit..."
12
+ if system("git rebase -X ours --onto #{sha}^ #{sha}")
13
+ log "Successfully removed bad commit...".green
14
+ log "Re-testing build...".green
15
+ system("bummr test")
16
+ else
17
+ log "Could not automatically remove this commit!".red
18
+ log "Please resolve conflicts, then 'git rebase --continue'."
19
+ log "Run 'bummr test' again once the rebase is complete"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def commit_message_for(sha)
26
+ `git log --pretty=format:'%s' -n 1 #{sha}`
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ module Bummr
2
+ class Updater
3
+ def initialize(outdated_gems)
4
+ @outdated_gems = outdated_gems
5
+ end
6
+
7
+ def update_gems
8
+ puts "Updating outdated gems".green
9
+
10
+ @outdated_gems.each_with_index do |gem, index|
11
+ update_gem(gem, index)
12
+ end
13
+ end
14
+
15
+ def update_gem(gem, index)
16
+ puts "Updating #{gem[:name]}: #{index+1} of #{@outdated_gems.count}"
17
+ system("bundle update #{gem[:name]}")
18
+
19
+ updated_version = updated_version_for(gem)
20
+ message = "Update #{gem[:name]} from #{gem[:installed]} to #{updated_version}"
21
+
22
+ if gem[:installed] == updated_version
23
+ log("#{gem[:name]} not updated")
24
+ return
25
+ end
26
+
27
+ if gem[:newest] != updated_version
28
+ log("#{gem[:name]} not updated from #{gem[:installed]} to latest: #{gem[:newest]}")
29
+ end
30
+
31
+ log "Commit: #{message}".green
32
+ system("git commit -am '#{message}'")
33
+ end
34
+
35
+ def updated_version_for(gem)
36
+ `bundle list | grep " #{gem[:name]} "`.split('(')[1].split(')')[0]
37
+ end
38
+ end
39
+ end
40
+
data/lib/bummr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bummr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/bummr.rb CHANGED
@@ -1,3 +1,15 @@
1
- require "bummr/version"
2
- require "bummr/cli"
1
+ # grouped by dependency order than alpha
2
+ require "bummr/log"
3
+ require 'colorize'
4
+ require 'open3'
5
+ require 'singleton'
6
+ require 'thor'
7
+
8
+ require "bummr/bisecter"
9
+ require "bummr/check"
3
10
  require "bummr/outdated"
11
+ require "bummr/rebaser"
12
+ require "bummr/updater"
13
+
14
+ require "bummr/cli"
15
+ require "bummr/version"
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bummr::Check do
4
+ let(:check) { Bummr::Check.instance }
5
+
6
+ before(:each) do
7
+ allow(check)
8
+ .to receive(:check_master).and_return(nil)
9
+ allow(check)
10
+ .to receive(:check_log).and_return(nil)
11
+ allow(check)
12
+ .to receive(:check_status).and_return(nil)
13
+ allow(check)
14
+ .to receive(:check_diff).and_return(nil)
15
+ allow(check).to receive(:puts)
16
+ allow(check).to receive(:yes?).and_return(false)
17
+ allow(check).to receive(:exit).and_return(false)
18
+ end
19
+
20
+ describe "#check" do
21
+ context "all checks pass" do
22
+ context "not full check" do
23
+ it "returns 'Ready to run bummr.' and proceeds" do
24
+ check.check
25
+
26
+ expect(check).to have_received(:puts).with("Ready to run bummr.".green)
27
+ end
28
+ end
29
+
30
+ context "full check" do
31
+ it "returns 'Ready to run bummr.' and proceeds" do
32
+ check.check(true)
33
+
34
+ expect(check).to have_received(:puts).with("Ready to run bummr.".green)
35
+ end
36
+ end
37
+ end
38
+
39
+ context "check_master fails" do
40
+ it "reports the error and exits after confirm" do
41
+ allow(check)
42
+ .to receive(:check_master).and_call_original
43
+ allow(check).to receive(:`).with('git rev-parse --abbrev-ref HEAD')
44
+ .and_return "master\n"
45
+
46
+ check.check
47
+
48
+ expect(check).to have_received(:puts)
49
+ .with("Bummr is not meant to be run on master".red)
50
+ expect(check).to have_received(:yes?)
51
+ expect(check).to have_received(:exit).with(0)
52
+ end
53
+ end
54
+
55
+ context "check_log fails" do
56
+ it "reports the error and exits after confirm" do
57
+ allow(check)
58
+ .to receive(:check_log).and_call_original
59
+ allow(File).to receive(:directory?).with('log')
60
+ .and_return false
61
+
62
+ check.check
63
+
64
+ expect(check).to have_received(:puts)
65
+ .with("There is no log directory or you are not in the root".red)
66
+ expect(check).to have_received(:yes?)
67
+ expect(check).to have_received(:exit).with(0)
68
+ end
69
+ end
70
+
71
+ context "check_status fails" do
72
+ context "due to bisecting" do
73
+ before do
74
+ allow(check)
75
+ .to receive(:check_status).and_call_original
76
+ allow(check).to receive(:`).with('git status')
77
+ .and_return "are currently bisecting"
78
+ end
79
+
80
+ it "reports the error and exits after confirm" do
81
+ check.check
82
+
83
+ expect(check).to have_received(:puts)
84
+ .with("You are already bisecting. Make sure `git status` is clean".red)
85
+ expect(check).to have_received(:yes?)
86
+ expect(check).to have_received(:exit).with(0)
87
+ end
88
+ end
89
+
90
+ context "due to rebasing" do
91
+ before do
92
+ allow(check).to receive(:check_status).and_call_original
93
+ allow(check).to receive(:`).with('git status')
94
+ .and_return "are currently rebasing"
95
+ end
96
+
97
+ it "reports the error and exits after confirm" do
98
+ check.check
99
+
100
+ expect(check).to have_received(:puts)
101
+ .with("You are already rebasing. Make sure `git status` is clean".red)
102
+ expect(check).to have_received(:yes?)
103
+ expect(check).to have_received(:exit).with(0)
104
+ end
105
+ end
106
+ end
107
+
108
+ context "check_diff fails" do
109
+ before do
110
+ allow(check).to receive(:check_diff).and_call_original
111
+ allow(check).to receive(:`).with('git diff master')
112
+ .and_return "+ file"
113
+ end
114
+
115
+ it "reports the error and exits after confirm" do
116
+ check.check(true)
117
+
118
+ expect(check).to have_received(:puts)
119
+ .with("Please make sure that `git diff master` returns empty".red)
120
+ expect(check).to have_received(:yes?)
121
+ expect(check).to have_received(:exit).with(0)
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bummr::Bisecter do
4
+ let(:std_out_err_bad_commit) {
5
+ output = String.new
6
+ output += "mybadcommit is the first bad commit\n"
7
+ output += "bisect run success\n"
8
+ StringIO.new(output)
9
+ }
10
+ let(:bisecter) { described_class.instance }
11
+ let(:rebaser) { Bummr::Rebaser.instance }
12
+
13
+ before do
14
+ allow(STDOUT).to receive(:puts)
15
+ allow(bisecter).to receive(:system).with("bundle")
16
+ allow(bisecter).to receive(:system)
17
+ end
18
+
19
+ describe "#bisect" do
20
+ context "bad commit" do
21
+ it "rebases it out" do
22
+ allow(Open3).to receive(:popen2e).and_yield(nil, std_out_err_bad_commit)
23
+ allow(rebaser).to receive(:remove_commit)
24
+ .with("mybadcommit")
25
+
26
+ bisecter.bisect
27
+
28
+ expect(rebaser).to have_received(:remove_commit).with("mybadcommit")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bummr::CLI do
4
+ # https://github.com/wireframe/gitx/blob/171da367072b0e82d5906d1e5b3f8ff38e5774e7/spec/thegarage/gitx/cli/release_command_spec.rb#L9
5
+ let(:args) { [] }
6
+ let(:options) { {} }
7
+ let(:config) { { pretend: true } }
8
+ let(:cli) { described_class.new(args, options, config) }
9
+ let(:outdated_gems) {
10
+ [
11
+ { name: "myGem", installed: "0.3.2", newest: "0.3.5" },
12
+ { name: "otherGem", installed: "1.3.2.23", newest: "1.6.5" },
13
+ { name: "thirdGem", installed: "4.3.4", newest: "5.6.45" },
14
+ ]
15
+ }
16
+
17
+ describe "#update" do
18
+ context "when user rejects moving forward" do
19
+ it "does not attempt to move forward" do
20
+ expect(cli).to receive(:yes?).and_return(false)
21
+ expect(cli).not_to receive(:check)
22
+
23
+ cli.update
24
+ end
25
+ end
26
+
27
+ context "when user agrees to move forward" do
28
+ context "and there are no outdated gems" do
29
+ it "informs that there are no outdated gems" do
30
+ allow_any_instance_of(Bummr::Outdated).to receive(:outdated_gems)
31
+ .and_return []
32
+
33
+ expect(cli).to receive(:ask_questions)
34
+ expect(cli).to receive(:yes?).and_return(true)
35
+ expect(cli).to receive(:check)
36
+ expect(cli).to receive(:log)
37
+ expect(cli).to receive(:system).with("bundle")
38
+ expect(cli).to receive(:puts).with("No outdated gems to update".green)
39
+
40
+ cli.update
41
+ end
42
+ end
43
+
44
+ context "and there are outdated gems" do
45
+ it "calls 'update' on the updater" do
46
+ allow_any_instance_of(Bummr::Outdated).to receive(:outdated_gems)
47
+ .and_return outdated_gems
48
+ updater = double
49
+ allow(updater).to receive(:update_gems)
50
+
51
+ expect(cli).to receive(:ask_questions)
52
+ expect(cli).to receive(:yes?).and_return(true)
53
+ expect(cli).to receive(:check)
54
+ expect(cli).to receive(:log)
55
+ expect(cli).to receive(:system).with("bundle")
56
+ expect(Bummr::Updater).to receive(:new).with(outdated_gems).and_return updater
57
+ expect(cli).to receive(:system).with("git rebase -i master")
58
+ expect(cli).to receive(:test)
59
+
60
+ cli.update
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#test" do
67
+ before do
68
+ allow(STDOUT).to receive(:puts)
69
+ allow(cli).to receive(:check)
70
+ allow(cli).to receive(:system)
71
+ allow(cli).to receive(:bisect)
72
+ end
73
+
74
+ context "build passes" do
75
+ it "reports that it passed the build, does not bisect" do
76
+ allow(cli).to receive(:system).with("bundle exec rake").and_return true
77
+
78
+ cli.test
79
+
80
+ expect(cli).to have_received(:check).with(false)
81
+ expect(cli).to have_received(:system).with("bundle")
82
+ expect(cli).to have_received(:system).with("bundle exec rake")
83
+ expect(cli).not_to have_received(:bisect)
84
+ end
85
+ end
86
+
87
+ context "build fails" do
88
+ it "bisects" do
89
+ allow(cli).to receive(:system).with("bundle exec rake").and_return false
90
+
91
+ cli.test
92
+
93
+ expect(cli).to have_received(:check).with(false)
94
+ expect(cli).to have_received(:system).with("bundle")
95
+ expect(cli).to have_received(:system).with("bundle exec rake")
96
+ expect(cli).to have_received(:bisect)
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#bisect" do
102
+ it "calls Bummr:Bisecter.instance.bisect" do
103
+ allow(cli).to receive(:check)
104
+ allow_any_instance_of(Bummr::Bisecter).to receive(:bisect)
105
+ bisecter = Bummr::Bisecter.instance
106
+
107
+ cli.bisect
108
+
109
+ expect(bisecter).to have_received(:bisect)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Bummr::Log do
4
+ let(:object) { Object.new }
5
+ let(:message) { "test message" }
6
+
7
+ before do
8
+ `mkdir -p log`
9
+ object.extend(Bummr::Log)
10
+ end
11
+
12
+ after do
13
+ `rm log/bummr.log`
14
+ end
15
+
16
+ describe "#log" do
17
+ it "puts the message" do
18
+ allow(STDOUT).to receive(:puts)
19
+
20
+ object.log message
21
+
22
+ expect(STDOUT).to have_received(:puts).with(message)
23
+ end
24
+
25
+ it "outputs the message to log/bummr.log" do
26
+ object.log message
27
+
28
+ result = `cat log/bummr.log`
29
+
30
+ expect(result).to eq message + "\n"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bummr::Outdated do
4
+ # https://github.com/wireframe/gitx/blob/8e3cdc8b5d0c2082ed3daaf2fc054654b2e7a6c8/spec/gitx/executor_spec.rb#L9
5
+ let(:stdoutput) {
6
+ output = String.new
7
+ output += " * devise (newest 4.1.1, installed 3.5.2) in group \"default\"\n"
8
+ output += " * rake (newest 11.1.2, installed 10.4.2)\n"
9
+ output += " * rails (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0) in group \"default\"\n"
10
+ StringIO.new(output)
11
+ }
12
+
13
+ let(:gemfile) {
14
+ gemfile = String.new
15
+ gemfile += "gem 'devise'\n"
16
+ gemfile += "gem 'rake'\n"
17
+ gemfile += "gem 'rails'\n"
18
+ gemfile
19
+ }
20
+
21
+ describe "#outdated_gems" do
22
+ it "Correctly identifies outdated gems" do
23
+ allow(Open3).to receive(:popen2).and_yield(nil, stdoutput)
24
+ allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile
25
+
26
+ instance = Bummr::Outdated.instance
27
+ result = instance.outdated_gems
28
+
29
+ expect(result[0][:name]).to eq('devise')
30
+ expect(result[0][:newest]).to eq('4.1.1')
31
+ expect(result[0][:installed]).to eq('3.5.2')
32
+
33
+ expect(result[1][:name]).to eq('rake')
34
+ expect(result[1][:newest]).to eq('11.1.2')
35
+ expect(result[1][:installed]).to eq('10.4.2')
36
+
37
+ expect(result[2][:name]).to eq('rails')
38
+ expect(result[2][:newest]).to eq('4.2.6')
39
+ expect(result[2][:installed]).to eq('4.2.5.1')
40
+ end
41
+ end
42
+
43
+ describe "#parse_gem_from" do
44
+ it 'line' do
45
+ line = ' * devise (newest 4.1.1, installed 3.5.2) in group "default"'
46
+
47
+ gem = Bummr::Outdated.instance.parse_gem_from(line)
48
+
49
+ expect(gem[:name]).to eq('devise')
50
+ expect(gem[:newest]).to eq('4.1.1')
51
+ expect(gem[:installed]).to eq('3.5.2')
52
+ end
53
+
54
+ it 'line in group' do
55
+ line = ' * rake (newest 11.1.2, installed 10.4.2)'
56
+
57
+ gem = Bummr::Outdated.instance.parse_gem_from(line)
58
+
59
+ expect(gem[:name]).to eq('rake')
60
+ expect(gem[:newest]).to eq('11.1.2')
61
+ expect(gem[:installed]).to eq('10.4.2')
62
+ end
63
+
64
+ it 'line with requested' do
65
+ line = ' * rails (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0) in group "default"'
66
+
67
+ gem = Bummr::Outdated.instance.parse_gem_from(line)
68
+
69
+ expect(gem[:name]).to eq('rails')
70
+ expect(gem[:newest]).to eq('4.2.6')
71
+ expect(gem[:installed]).to eq('4.2.5.1')
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe Bummr::Rebaser do
4
+ # let(:commit_message) { "test commit message" }
5
+ let(:rebaser) { Bummr::Rebaser.instance }
6
+ let(:sha) { "testsha" }
7
+ let(:rebase_command) { "git rebase -X ours --onto #{sha}^ #{sha}" }
8
+
9
+ before do
10
+ allow(rebaser).to receive(:commit_message_for).and_return "commit message"
11
+ allow(rebaser).to receive(:log)
12
+ allow(rebaser).to receive(:system)
13
+ end
14
+
15
+ describe "#remove_commit" do
16
+ it "logs the bad commit" do
17
+ rebaser.remove_commit(sha)
18
+
19
+ expect(rebaser).to have_received(:log).with(
20
+ "Bad commit: commit message, #{sha}".red
21
+ )
22
+ end
23
+
24
+ it "resets the bisection" do
25
+ rebaser.remove_commit(sha)
26
+
27
+ expect(rebaser).to have_received(:system).with("git bisect reset")
28
+ end
29
+
30
+ context "successfully rebases the commit out" do
31
+ before(:each) do
32
+ allow(rebaser).to receive(:system).with(rebase_command).and_return true
33
+ end
34
+
35
+ it "logs the successful result" do
36
+ rebaser.remove_commit(sha)
37
+
38
+ expect(rebaser).to have_received(:log).with(
39
+ "Successfully removed bad commit...".green
40
+ )
41
+ end
42
+
43
+ it "tests the build again" do
44
+ rebaser.remove_commit(sha)
45
+
46
+ expect(rebaser).to have_received(:system).with "bummr test"
47
+ end
48
+ end
49
+
50
+ context "fails to rebase the commit out" do
51
+ before(:each) do
52
+ allow(rebaser).to receive(:system).with(rebase_command).and_return false
53
+ end
54
+
55
+ it "logs the failure to rebase" do
56
+ rebaser.remove_commit(sha)
57
+
58
+ expect(rebaser).to have_received(:log).with(
59
+ "Could not automatically remove this commit!".red
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,133 @@
1
+ require "spec_helper"
2
+
3
+ describe Bummr::Updater do
4
+ let(:outdated_gems) {
5
+ [
6
+ { name: "myGem", installed: "0.3.2", newest: "0.3.5" },
7
+ { name: "otherGem", installed: "1.3.2.23", newest: "1.6.5" },
8
+ { name: "thirdGem", installed: "4.3.4", newest: "5.6.45" },
9
+ ]
10
+ }
11
+ let(:gem) { outdated_gems[0] }
12
+ let(:updater) { described_class.new(outdated_gems) }
13
+ let(:newest) { outdated_gems[0][:newest] }
14
+ let(:installed) { outdated_gems[0][:installed] }
15
+ let(:intermediate_version) { "0.3.4" }
16
+ let(:update_cmd) { "bundle update #{gem[:name]}" }
17
+
18
+ describe "#update_gems" do
19
+ it "calls update_gem on each gem" do
20
+ allow(updater).to receive(:update_gem)
21
+
22
+ updater.update_gems
23
+
24
+ outdated_gems.each_with_index do |gem, index|
25
+ expect(updater).to have_received(:update_gem).with(gem, index)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#update_gem" do
31
+ it "attempts to update the gem" do
32
+ allow(updater).to receive(:system).with(update_cmd)
33
+ allow(updater).to receive(:updated_version_for).with(gem).and_return installed
34
+ allow(updater).to receive(:log)
35
+
36
+ updater.update_gem(gem, 0)
37
+ end
38
+
39
+ context "not updated at all" do
40
+ it "logs that it's not updated to the latest" do
41
+ allow(updater).to receive(:system).with(update_cmd)
42
+ allow(updater).to receive(:updated_version_for).with(gem).and_return installed
43
+ allow(updater).to receive(:log)
44
+
45
+ updater.update_gem(gem, 0)
46
+
47
+ expect(updater).to have_received(:log).with("#{gem[:name]} not updated")
48
+ end
49
+
50
+ it "doesn't commit anything" do
51
+ allow(updater).to receive(:system).with(update_cmd)
52
+ allow(updater).to receive(:updated_version_for).with(gem).and_return installed
53
+ allow(updater).to receive(:log)
54
+
55
+ updater.update_gem(gem, 0)
56
+
57
+ expect(updater).to_not have_received(:system).with /git commit/
58
+ end
59
+ end
60
+
61
+ context "not updated to the newest version" do
62
+ before(:each) do
63
+ allow(updater).to receive(:updated_version_for).with(gem).and_return(
64
+ intermediate_version
65
+ )
66
+ end
67
+
68
+ it "logs that it's not updated to the latest" do
69
+ not_latest_message =
70
+ "#{gem[:name]} not updated from #{gem[:installed]} to latest: #{gem[:newest]}"
71
+ allow(updater).to receive(:system)
72
+ allow(updater).to receive(:log)
73
+
74
+ updater.update_gem(gem, 0)
75
+
76
+ expect(updater).to have_received(:log).with not_latest_message
77
+ end
78
+
79
+ it "commits" do
80
+ commit_message =
81
+ "'Update #{gem[:name]} from #{gem[:installed]} to #{intermediate_version}'"
82
+ allow(updater).to receive(:system)
83
+ allow(updater).to receive(:log)
84
+
85
+ updater.update_gem(gem, 0)
86
+
87
+ expect(updater).to have_received(:system).with(
88
+ "git commit -am #{commit_message}"
89
+ )
90
+ end
91
+ end
92
+
93
+ context "updated the gem to the latest" do
94
+ before(:each) do
95
+ allow(updater).to receive(:updated_version_for).and_return newest
96
+ end
97
+
98
+ it "logs the commit" do
99
+ commit_message =
100
+ "Commit: Update #{gem[:name]} from #{gem[:installed]} to #{gem[:newest]}".green
101
+ allow(updater).to receive(:system)
102
+ allow(updater).to receive(:log)
103
+
104
+ updater.update_gem(gem, 0)
105
+
106
+ expect(updater).to have_received(:log).with commit_message
107
+ end
108
+
109
+ it "commits" do
110
+ commit_message =
111
+ "Update #{gem[:name]} from #{gem[:installed]} to #{gem[:newest]}"
112
+ allow(updater).to receive(:system)
113
+ allow(updater).to receive(:log)
114
+
115
+ updater.update_gem(gem, 0)
116
+
117
+ expect(updater).to have_received(:system).with(
118
+ "git commit -am '#{commit_message}'"
119
+ )
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "#updated_version_for" do
125
+ it "returns the correct version from bundle list" do
126
+ allow(updater).to receive(:`).with(
127
+ "bundle list | grep \" #{gem[:name]} \""
128
+ ).and_return(" * #{gem[:name]} (3.5.2)\n")
129
+
130
+ expect(updater.updated_version_for(gem)).to eq "3.5.2"
131
+ end
132
+ end
133
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
1
3
  require 'pry'
2
4
  require 'bummr'
5
+ require 'colorize'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bummr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Pender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: spring
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: codeclimate-test-reporter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: See Readme
154
182
  email:
155
183
  - lpender@gmail.com
@@ -166,10 +194,21 @@ files:
166
194
  - bin/bummr
167
195
  - bummr.gemspec
168
196
  - lib/bummr.rb
197
+ - lib/bummr/bisecter.rb
198
+ - lib/bummr/check.rb
169
199
  - lib/bummr/cli.rb
200
+ - lib/bummr/log.rb
170
201
  - lib/bummr/outdated.rb
202
+ - lib/bummr/rebaser.rb
203
+ - lib/bummr/updater.rb
171
204
  - lib/bummr/version.rb
172
- - spec/outdated_spec.rb
205
+ - spec/check_spec.rb
206
+ - spec/lib/bisecter_spec.rb
207
+ - spec/lib/cli_spec.rb
208
+ - spec/lib/log_spec.rb
209
+ - spec/lib/outdated_spec.rb
210
+ - spec/lib/rebaser_spec.rb
211
+ - spec/lib/updater_spec.rb
173
212
  - spec/spec_helper.rb
174
213
  homepage: https://github.com/lpender/bummr
175
214
  licenses:
@@ -196,5 +235,11 @@ signing_key:
196
235
  specification_version: 4
197
236
  summary: Helper script to intelligently update your Gemfile
198
237
  test_files:
199
- - spec/outdated_spec.rb
238
+ - spec/check_spec.rb
239
+ - spec/lib/bisecter_spec.rb
240
+ - spec/lib/cli_spec.rb
241
+ - spec/lib/log_spec.rb
242
+ - spec/lib/outdated_spec.rb
243
+ - spec/lib/rebaser_spec.rb
244
+ - spec/lib/updater_spec.rb
200
245
  - spec/spec_helper.rb
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bummr::Outdated do
4
- describe "#parse_gem_from" do
5
- it 'line' do
6
- line = ' * devise (newest 4.1.1, installed 3.5.2) in group "default"'
7
-
8
- gem = Bummr::Outdated.instance.parse_gem_from(line)
9
-
10
- expect(gem[:name]).to eq('devise')
11
- expect(gem[:newest]).to eq('4.1.1')
12
- expect(gem[:installed]).to eq('3.5.2')
13
- end
14
-
15
- it 'line in group' do
16
- line = ' * rake (newest 11.1.2, installed 10.4.2)'
17
-
18
- gem = Bummr::Outdated.instance.parse_gem_from(line)
19
-
20
- expect(gem[:name]).to eq('rake')
21
- expect(gem[:newest]).to eq('11.1.2')
22
- expect(gem[:installed]).to eq('10.4.2')
23
- end
24
- end
25
- end