bummr 0.3.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/bummr/updater.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Bummr
2
2
  class Updater
3
3
  include Log
4
+ include Scm
4
5
 
5
6
  def initialize(outdated_gems)
6
7
  @outdated_gems = outdated_gems
@@ -19,7 +20,12 @@ module Bummr
19
20
  system("bundle update #{gem[:name]}")
20
21
 
21
22
  updated_version = updated_version_for(gem)
22
- message = "Update #{gem[:name]} from #{gem[:installed]} to #{updated_version}"
23
+
24
+ if (updated_version)
25
+ message = "Update #{gem[:name]} from #{gem[:installed]} to #{updated_version}"
26
+ else
27
+ message = "Update dependencies for #{gem[:name]}"
28
+ end
23
29
 
24
30
  if gem[:installed] == updated_version
25
31
  log("#{gem[:name]} not updated")
@@ -30,12 +36,17 @@ module Bummr
30
36
  log("#{gem[:name]} not updated from #{gem[:installed]} to latest: #{gem[:newest]}")
31
37
  end
32
38
 
33
- log "Commit: #{message}".color(:green)
34
- system("git commit -am '#{message}'")
39
+ git.add("Gemfile")
40
+ git.add("Gemfile.lock")
41
+ git.add("vendor/cache")
42
+ git.commit(message)
35
43
  end
36
44
 
37
45
  def updated_version_for(gem)
38
- `bundle list | grep " #{gem[:name]} "`.split('(')[1].split(')')[0]
46
+ begin
47
+ `bundle list | grep " #{gem[:name]} "`.split('(')[1].split(')')[0]
48
+ rescue Error
49
+ end
39
50
  end
40
51
  end
41
52
  end
data/lib/bummr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bummr
2
- VERSION = "0.3.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/bummr.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # grouped by dependency order than alpha
2
2
  require 'bummr/log'
3
+ require 'bummr/prompt'
4
+ require "bummr/scm"
3
5
  require 'rainbow/ext/string'
4
6
  require 'open3'
5
7
  require 'singleton'
@@ -7,8 +9,9 @@ require 'thor'
7
9
 
8
10
  require "bummr/bisecter"
9
11
  require "bummr/check"
12
+ require "bummr/git"
10
13
  require "bummr/outdated"
11
- require "bummr/rebaser"
14
+ require "bummr/remover"
12
15
  require "bummr/updater"
13
16
 
14
17
  require "bummr/cli"
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+ require "jet_black"
3
+
4
+ describe "bummr update command" do
5
+ let(:session) { JetBlack::Session.new(options: { clean_bundler_env: true }) }
6
+ let(:bummr_gem_path) { File.expand_path("../../", __dir__) }
7
+
8
+ it "updates outdated gems" do
9
+ session.create_file "Gemfile", <<~RUBY
10
+ source "https://rubygems.org"
11
+ gem "rake", "~> 10.0"
12
+ gem "bummr", path: "#{bummr_gem_path}"
13
+ RUBY
14
+
15
+ session.create_file "Rakefile", <<~RUBY
16
+ task :default do
17
+ puts "Hello from the Rakefile"
18
+ end
19
+ RUBY
20
+
21
+ expect(session.run("bundle install --retry 3")).
22
+ to be_a_success.and have_stdout(/bummr .* from source/)
23
+
24
+ # Now allow newer versions of Rake to be installed
25
+ session.run("sed -i.bak 's/, \"~> 10.0\"//' Gemfile")
26
+
27
+ session.run("mkdir -p log")
28
+
29
+ expect(session.run("git init .")).
30
+ to be_a_success.and have_stdout("Initialized empty Git repository")
31
+
32
+ session.run("git config user.name 'Bummr Test'")
33
+ session.run("git config user.email 'test@example.com'")
34
+
35
+ expect(session.run("git add . && git commit -m 'Initial commit'")).
36
+ to be_a_success.and have_stdout("Initial commit")
37
+
38
+ session.run("git checkout -b bummr-branch")
39
+
40
+ update_result = session.run(
41
+ "bundle exec bummr update",
42
+ stdin: "y\ny\ny\n",
43
+ env: { EDITOR: nil, BUMMR_HEADLESS: "true" },
44
+ )
45
+
46
+ rake_gem_updated = /Update rake from 10\.\d\.\d to 1[1-9]\.\d\.\d/
47
+
48
+ expect(update_result).
49
+ to be_a_success.and have_stdout(rake_gem_updated)
50
+
51
+ expect(update_result).to have_stdout("Passed the build!")
52
+
53
+ expect(session.run("git log")).
54
+ to be_a_success.and have_stdout(rake_gem_updated)
55
+
56
+ expect(session.run("bundle show")).
57
+ to be_a_success.and have_stdout(/rake\s\(1[1-9]/)
58
+ end
59
+ end
@@ -8,7 +8,7 @@ describe Bummr::Bisecter do
8
8
  StringIO.new(output)
9
9
  }
10
10
  let(:bisecter) { described_class.instance }
11
- let(:rebaser) { Bummr::Rebaser.instance }
11
+ let(:remover) { Bummr::Remover.instance }
12
12
 
13
13
  before do
14
14
  allow(STDOUT).to receive(:puts)
@@ -20,12 +20,12 @@ describe Bummr::Bisecter do
20
20
  context "bad commit" do
21
21
  it "rebases it out" do
22
22
  allow(Open3).to receive(:popen2e).and_yield(nil, std_out_err_bad_commit)
23
- allow(rebaser).to receive(:remove_commit)
23
+ allow(remover).to receive(:remove_commit)
24
24
  .with("mybadcommit")
25
25
 
26
26
  bisecter.bisect
27
27
 
28
- expect(rebaser).to have_received(:remove_commit).with("mybadcommit")
28
+ expect(remover).to have_received(:remove_commit).with("mybadcommit")
29
29
  end
30
30
  end
31
31
  end
data/spec/lib/cli_spec.rb CHANGED
@@ -6,6 +6,7 @@ describe Bummr::CLI do
6
6
  let(:options) { {} }
7
7
  let(:config) { { pretend: true } }
8
8
  let(:cli) { described_class.new(args, options, config) }
9
+ let(:git) { Bummr::Git.instance }
9
10
  let(:outdated_gems) {
10
11
  [
11
12
  { name: "myGem", installed: "0.3.2", newest: "0.3.5" },
@@ -29,14 +30,14 @@ describe Bummr::CLI do
29
30
  updater = double
30
31
  allow(updater).to receive(:update_gems)
31
32
 
32
- expect(cli).to receive(:ask_questions)
33
+ expect(cli).to receive(:display_info)
33
34
  expect(cli).to receive(:yes?).and_return(true)
34
35
  expect(cli).to receive(:check)
35
36
  expect(cli).to receive(:log)
36
- expect(cli).to receive(:system).with("bundle")
37
+ expect(cli).to receive(:system).with("bundle install")
37
38
  expect(Bummr::Updater).to receive(:new).with(outdated_gems).and_return updater
38
- expect(cli).to receive(:system).with("git rebase -i #{BASE_BRANCH}")
39
39
  expect(cli).to receive(:test)
40
+ expect(git).to receive(:rebase_interactive).with(BASE_BRANCH)
40
41
  end
41
42
 
42
43
  context "and there are no outdated gems" do
@@ -44,11 +45,11 @@ describe Bummr::CLI do
44
45
  allow_any_instance_of(Bummr::Outdated).to receive(:outdated_gems)
45
46
  .and_return []
46
47
 
47
- expect(cli).to receive(:ask_questions)
48
+ expect(cli).to receive(:display_info)
48
49
  expect(cli).to receive(:yes?).and_return(true)
49
50
  expect(cli).to receive(:check)
50
51
  expect(cli).to receive(:log)
51
- expect(cli).to receive(:system).with("bundle")
52
+ expect(cli).to receive(:system).with("bundle install")
52
53
  expect(cli).to receive(:puts).with("No outdated gems to update".color(:green))
53
54
 
54
55
  cli.update
@@ -93,6 +94,38 @@ describe Bummr::CLI do
93
94
  cli.update
94
95
  end
95
96
  end
97
+
98
+ describe "gem option" do
99
+ it "requests only outdated specific gem from supplied be listed" do
100
+ options[:gem] = 'tzdata'
101
+
102
+ expect_any_instance_of(Bummr::Outdated)
103
+ .to receive(:outdated_gems).with(hash_including({ gem: 'tzdata' }))
104
+ .and_return outdated_gems
105
+
106
+ mock_bummr_standard_flow
107
+
108
+ cli.update
109
+ end
110
+ end
111
+ end
112
+
113
+ context "when in headless mode" do
114
+ context "and there are no outdated gems" do
115
+ it "informs that there are no outdated gems" do
116
+ stub_const("HEADLESS", true)
117
+ allow_any_instance_of(Bummr::Outdated).to receive(:outdated_gems)
118
+ .and_return []
119
+
120
+ expect(cli).to receive(:display_info)
121
+ expect(cli).to receive(:check)
122
+ expect(cli).to receive(:log)
123
+ expect(cli).to receive(:system).with("bundle install")
124
+ expect(cli).to receive(:puts).with("No outdated gems to update".color(:green))
125
+
126
+ cli.update
127
+ end
128
+ end
96
129
  end
97
130
  end
98
131
 
@@ -102,6 +135,7 @@ describe Bummr::CLI do
102
135
  allow(cli).to receive(:check)
103
136
  allow(cli).to receive(:system)
104
137
  allow(cli).to receive(:bisect)
138
+ allow(cli).to receive(:yes?).and_return true
105
139
  end
106
140
 
107
141
  context "build passes" do
@@ -111,7 +145,7 @@ describe Bummr::CLI do
111
145
  cli.test
112
146
 
113
147
  expect(cli).to have_received(:check).with(false)
114
- expect(cli).to have_received(:system).with("bundle")
148
+ expect(cli).to have_received(:system).with("bundle install")
115
149
  expect(cli).to have_received(:system).with("bundle exec rake")
116
150
  expect(cli).not_to have_received(:bisect)
117
151
  end
@@ -124,7 +158,7 @@ describe Bummr::CLI do
124
158
  cli.test
125
159
 
126
160
  expect(cli).to have_received(:check).with(false)
127
- expect(cli).to have_received(:system).with("bundle")
161
+ expect(cli).to have_received(:system).with("bundle install")
128
162
  expect(cli).to have_received(:system).with("bundle exec rake")
129
163
  expect(cli).to have_received(:bisect)
130
164
  end
@@ -134,6 +168,7 @@ describe Bummr::CLI do
134
168
  describe "#bisect" do
135
169
  it "calls Bummr:Bisecter.instance.bisect" do
136
170
  allow(cli).to receive(:check)
171
+ allow(cli).to receive(:yes?).and_return true
137
172
  allow_any_instance_of(Bummr::Bisecter).to receive(:bisect)
138
173
  bisecter = Bummr::Bisecter.instance
139
174
 
@@ -0,0 +1,88 @@
1
+ require "spec_helper"
2
+
3
+ describe Bummr::Git do
4
+ describe "#add" do
5
+ it "stages specified files with git" do
6
+ git = stub_git
7
+ files = "Gemfile Gemfile.lock"
8
+
9
+ git.add(files)
10
+
11
+ expect(git).to have_received(:system).with(
12
+ "git add #{files}"
13
+ )
14
+ end
15
+ end
16
+
17
+ describe "#commit" do
18
+ it "logs the commit" do
19
+ git = stub_git
20
+ commit_message = "Update Foo from 0.0.1 to 0.0.2"
21
+
22
+ git.commit(commit_message)
23
+
24
+ expect(git).to have_received(:log).with(
25
+ /Commit: #{commit_message}/
26
+ )
27
+ end
28
+
29
+ it "commits with a message" do
30
+ git = stub_git
31
+ commit_message = "Update Foo from 0.0.1 to 0.0.2"
32
+
33
+ git.commit(commit_message)
34
+
35
+ expect(git).to have_received(:system).with(
36
+ "git commit -m '#{commit_message}'"
37
+ )
38
+ end
39
+
40
+ describe "when BUMMR_GIT_COMMIT is defined" do
41
+ it "commits using defined value" do
42
+ allow(ENV).to receive(:fetch).with("BUMMR_GIT_COMMIT").and_return("git commit --no-verify")
43
+ git = stub_git
44
+ commit_message = "Update Foo from 0.0.1 to 0.0.2"
45
+
46
+ git.commit(commit_message)
47
+
48
+ expect(git).to have_received(:system).with(
49
+ "git commit --no-verify -m '#{commit_message}'"
50
+ )
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "#rebase_interactive" do
56
+ it "runs git interactive rebase to the given sha" do
57
+ git = stub_git
58
+ sha = "b39dcd8"
59
+
60
+ git.rebase_interactive(sha)
61
+
62
+ expect(git).to have_received(:system).with(
63
+ "git rebase -i #{BASE_BRANCH}"
64
+ )
65
+ end
66
+ end
67
+
68
+ describe "#message" do
69
+ it "displays the commit message for a given sha" do
70
+ git = stub_git
71
+ sha = "b39dcd8"
72
+
73
+ git.message(sha)
74
+
75
+ expect(git).to have_received(:`).with(
76
+ "git log --pretty=format:'%s' -n 1 #{sha}"
77
+ )
78
+ end
79
+ end
80
+
81
+ def stub_git
82
+ git = Bummr::Git.clone.instance
83
+ allow(git).to receive(:log)
84
+ allow(git).to receive(:system)
85
+ allow(git).to receive(:`)
86
+ git
87
+ end
88
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Bummr::Outdated do
4
4
  # https://github.com/wireframe/gitx/blob/8e3cdc8b5d0c2082ed3daaf2fc054654b2e7a6c8/spec/gitx/executor_spec.rb#L9
5
- let(:stdoutput) {
5
+ let(:stdoutput_legacy) {
6
6
  output = String.new
7
7
  output += " * devise (newest 4.1.1, installed 3.5.2) in group \"default\"\n"
8
8
  output += " * rake (newest 11.1.2, installed 10.4.2)\n"
@@ -12,6 +12,11 @@ describe Bummr::Outdated do
12
12
  StringIO.new(output)
13
13
  }
14
14
 
15
+ let(:stdoutput) {
16
+ output = stdoutput_legacy.string.gsub(/^([\s*]+)/, "")
17
+ StringIO.new(output)
18
+ }
19
+
15
20
  let(:gemfile) {
16
21
  gemfile = String.new
17
22
  gemfile += "gem 'devise'\n"
@@ -22,33 +27,35 @@ describe Bummr::Outdated do
22
27
  }
23
28
 
24
29
  describe "#outdated_gems" do
25
- it "Correctly identifies outdated gems" do
26
- allow(Open3).to receive(:popen2).and_yield(nil, stdoutput)
27
- allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile
30
+ { bundler2: :stdoutput, bundler1: :stdoutput_legacy }.each_pair do |version, output|
31
+ it "Correctly identifies outdated gems with bundler #{version}" do
32
+ allow(Open3).to receive(:popen2).and_yield(nil, public_send(output))
33
+ allow_any_instance_of(described_class).to receive(:gemfile).and_return gemfile
28
34
 
29
- instance = Bummr::Outdated.instance
30
- result = instance.outdated_gems
35
+ instance = Bummr::Outdated.instance
36
+ result = instance.outdated_gems
31
37
 
32
- expect(result[0][:name]).to eq('devise')
33
- expect(result[0][:newest]).to eq('4.1.1')
34
- expect(result[0][:installed]).to eq('3.5.2')
38
+ expect(result[0][:name]).to eq('devise')
39
+ expect(result[0][:newest]).to eq('4.1.1')
40
+ expect(result[0][:installed]).to eq('3.5.2')
35
41
 
36
- expect(result[1][:name]).to eq('rake')
37
- expect(result[1][:newest]).to eq('11.1.2')
38
- expect(result[1][:installed]).to eq('10.4.2')
42
+ expect(result[1][:name]).to eq('rake')
43
+ expect(result[1][:newest]).to eq('11.1.2')
44
+ expect(result[1][:installed]).to eq('10.4.2')
39
45
 
40
- expect(result[2][:name]).to eq('rails')
41
- expect(result[2][:newest]).to eq('4.2.6')
42
- expect(result[2][:installed]).to eq('4.2.5.1')
46
+ expect(result[2][:name]).to eq('rails')
47
+ expect(result[2][:newest]).to eq('4.2.6')
48
+ expect(result[2][:installed]).to eq('4.2.5.1')
43
49
 
44
- expect(result[3][:name]).to eq('spring')
45
- expect(result[3][:newest]).to eq('4.2.6')
46
- expect(result[3][:installed]).to eq('4.2.5.1')
50
+ expect(result[3][:name]).to eq('spring')
51
+ expect(result[3][:newest]).to eq('4.2.6')
52
+ expect(result[3][:installed]).to eq('4.2.5.1')
53
+ end
47
54
  end
48
55
 
49
56
  describe "all gems option" do
50
57
  it "lists all outdated dependencies by omitting the strict option" do
51
- allow(Open3).to receive(:popen2).with("bundle outdated").and_yield(nil, stdoutput)
58
+ allow(Open3).to receive(:popen2).with("bundle outdated --parseable").and_yield(nil, stdoutput)
52
59
 
53
60
  allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile
54
61
 
@@ -59,7 +66,7 @@ describe Bummr::Outdated do
59
66
  end
60
67
 
61
68
  it "defaults to false" do
62
- expect(Open3).to receive(:popen2).with("bundle outdated --strict").and_yield(nil, stdoutput)
69
+ expect(Open3).to receive(:popen2).with("bundle outdated --parseable --strict").and_yield(nil, stdoutput)
63
70
 
64
71
  allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile
65
72
 
@@ -73,13 +80,13 @@ describe Bummr::Outdated do
73
80
  describe "group option" do
74
81
  let(:stdoutput_from_development_group) {
75
82
  output = String.new
76
- output += " * spring (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0)"
83
+ output += "spring (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0)"
77
84
  StringIO.new(output)
78
85
  }
79
86
 
80
87
  it "lists outdated gems only from supplied group" do
81
88
  allow(Open3).to receive(:popen2)
82
- .with("bundle outdated --strict --group development")
89
+ .with("bundle outdated --parseable --strict --group development")
83
90
  .and_yield(nil, stdoutput_from_development_group)
84
91
 
85
92
  allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile
@@ -92,7 +99,7 @@ describe Bummr::Outdated do
92
99
 
93
100
  it "defaults to all groups" do
94
101
  allow(Open3).to receive(:popen2)
95
- .with("bundle outdated --strict")
102
+ .with("bundle outdated --parseable --strict")
96
103
  .and_yield(nil, stdoutput)
97
104
 
98
105
  allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile
@@ -103,11 +110,32 @@ describe Bummr::Outdated do
103
110
  expect(gem_names).to include 'devise', 'rake', 'rails', 'spring'
104
111
  end
105
112
  end
113
+
114
+ describe "gem option" do
115
+ let(:stdoutput_from_spring_gem) {
116
+ output = String.new
117
+ output += "spring (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0)"
118
+ StringIO.new(output)
119
+ }
120
+
121
+ it "lists outdated gems only from supplied gem" do
122
+ allow(Open3).to receive(:popen2)
123
+ .with("bundle outdated --parseable --strict spring")
124
+ .and_yield(nil, stdoutput_from_spring_gem)
125
+
126
+ allow(Bummr::Outdated.instance).to receive(:gemfile).and_return gemfile
127
+
128
+ results = Bummr::Outdated.instance.outdated_gems(gem: :spring)
129
+ gem_names = results.map { |result| result[:name] }
130
+
131
+ expect(gem_names).to match_array ['spring']
132
+ end
133
+ end
106
134
  end
107
135
 
108
136
  describe "#parse_gem_from" do
109
137
  it 'line' do
110
- line = ' * devise (newest 4.1.1, installed 3.5.2) in group "default"'
138
+ line = 'devise (newest 4.1.1, installed 3.5.2) in group "default"'
111
139
 
112
140
  gem = Bummr::Outdated.instance.parse_gem_from(line)
113
141
 
@@ -117,7 +145,7 @@ describe Bummr::Outdated do
117
145
  end
118
146
 
119
147
  it 'line in group' do
120
- line = ' * rake (newest 11.1.2, installed 10.4.2)'
148
+ line = 'rake (newest 11.1.2, installed 10.4.2)'
121
149
 
122
150
  gem = Bummr::Outdated.instance.parse_gem_from(line)
123
151
 
@@ -127,7 +155,7 @@ describe Bummr::Outdated do
127
155
  end
128
156
 
129
157
  it 'line with requested' do
130
- line = ' * rails (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0) in group "default"'
158
+ line = 'rails (newest 4.2.6, installed 4.2.5.1, requested ~> 4.2.0) in group "default"'
131
159
 
132
160
  gem = Bummr::Outdated.instance.parse_gem_from(line)
133
161