bundler 1.6.0.pre.1 → 1.6.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -3
  3. data/Rakefile +12 -7
  4. data/lib/bundler.rb +3 -3
  5. data/lib/bundler/cli.rb +36 -619
  6. data/lib/bundler/cli/binstubs.rb +36 -0
  7. data/lib/bundler/cli/cache.rb +34 -0
  8. data/lib/bundler/cli/check.rb +35 -0
  9. data/lib/bundler/cli/clean.rb +19 -0
  10. data/lib/bundler/cli/common.rb +54 -0
  11. data/lib/bundler/cli/config.rb +84 -0
  12. data/lib/bundler/cli/console.rb +42 -0
  13. data/lib/bundler/cli/exec.rb +37 -0
  14. data/lib/bundler/cli/gem.rb +61 -0
  15. data/lib/bundler/cli/init.rb +33 -0
  16. data/lib/bundler/cli/inject.rb +33 -0
  17. data/lib/bundler/cli/install.rb +123 -0
  18. data/lib/bundler/cli/open.rb +25 -0
  19. data/lib/bundler/cli/outdated.rb +80 -0
  20. data/lib/bundler/cli/package.rb +36 -0
  21. data/lib/bundler/cli/platform.rb +43 -0
  22. data/lib/bundler/cli/show.rb +44 -0
  23. data/lib/bundler/cli/update.rb +73 -0
  24. data/lib/bundler/cli/viz.rb +27 -0
  25. data/lib/bundler/dsl.rb +46 -26
  26. data/lib/bundler/fetcher.rb +50 -4
  27. data/lib/bundler/installer.rb +1 -1
  28. data/lib/bundler/parallel_workers/worker.rb +1 -1
  29. data/lib/bundler/remote_specification.rb +1 -1
  30. data/lib/bundler/resolver.rb +30 -18
  31. data/lib/bundler/source/git.rb +0 -4
  32. data/lib/bundler/source/git/git_proxy.rb +2 -2
  33. data/lib/bundler/source/rubygems.rb +1 -14
  34. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +1 -1
  35. data/lib/bundler/vendor/thor/base.rb +1 -1
  36. data/lib/bundler/version.rb +1 -1
  37. data/spec/bundler/bundler_spec.rb +46 -47
  38. data/spec/bundler/{cli_rspec.rb → cli_spec.rb} +0 -1
  39. data/spec/bundler/definition_spec.rb +3 -7
  40. data/spec/bundler/dsl_spec.rb +43 -21
  41. data/spec/bundler/gem_helper_spec.rb +152 -123
  42. data/spec/bundler/retry_spec.rb +6 -7
  43. data/spec/bundler/settings_spec.rb +0 -2
  44. data/spec/bundler/source_spec.rb +4 -4
  45. data/spec/commands/newgem_spec.rb +7 -7
  46. data/spec/commands/outdated_spec.rb +11 -0
  47. data/spec/install/gems/dependency_api_spec.rb +41 -0
  48. data/spec/install/gems/simple_case_spec.rb +1 -17
  49. data/spec/other/ext_spec.rb +1 -1
  50. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  51. data/spec/support/builders.rb +43 -42
  52. data/spec/support/permissions.rb +0 -1
  53. data/spec/update/gems_spec.rb +11 -0
  54. metadata +51 -30
@@ -110,7 +110,7 @@ class Thor
110
110
  end
111
111
 
112
112
  # Whenever a class inherits from Thor or Thor::Group, we should track the
113
- # class and the file on Thor::Base. This is the method responsable for it.
113
+ # class and the file on Thor::Base. This is the method responsible for it.
114
114
  #
115
115
  def register_klass_file(klass) #:nodoc:
116
116
  file = caller[1].match(/(.*):\d+/)[1]
@@ -2,5 +2,5 @@ module Bundler
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.6.0.pre.1" unless defined?(::Bundler::VERSION)
5
+ VERSION = "1.6.0.pre.2" unless defined?(::Bundler::VERSION)
6
6
  end
@@ -4,71 +4,70 @@ require 'bundler'
4
4
 
5
5
  describe Bundler do
6
6
  describe "#load_gemspec_uncached" do
7
+ let(:app_gemspec_path) { tmp("test.gemspec") }
8
+ subject { Bundler.load_gemspec_uncached(app_gemspec_path) }
7
9
 
8
- before do
9
- @gemspec = tmp("test.gemspec")
10
- @gemspec.open('wb') do |f|
11
- f.write strip_whitespace(<<-GEMSPEC)
12
- ---
13
- {:!00 ao=gu\g1= 7~f
14
- GEMSPEC
10
+ context "with incorrect YAML file" do
11
+ before do
12
+ File.open(app_gemspec_path, "wb") do |f|
13
+ f.write strip_whitespace(<<-GEMSPEC)
14
+ ---
15
+ {:!00 ao=gu\g1= 7~f
16
+ GEMSPEC
17
+ end
15
18
  end
16
- end
17
19
 
18
- describe "on Ruby 1.8", :ruby => "1.8" do
19
- it "should catch YAML syntax errors" do
20
- expect { Bundler.load_gemspec_uncached(@gemspec) }.
21
- to raise_error(Bundler::GemspecError)
20
+ context "on Ruby 1.8", :ruby => "1.8" do
21
+ it "catches YAML syntax errors" do
22
+ expect { subject }.to raise_error(Bundler::GemspecError)
23
+ end
22
24
  end
23
- end
24
25
 
25
- context "on Ruby 1.9", :ruby => "1.9" do
26
- context "with Syck as YAML::Engine" do
27
- it "raises a GemspecError after YAML load throws ArgumentError" do
28
- orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
26
+ context "on Ruby 1.9", :ruby => "1.9" do
27
+ context "with Syck as YAML::Engine" do
28
+ it "raises a GemspecError after YAML load throws ArgumentError" do
29
+ orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
29
30
 
30
- expect { Bundler.load_gemspec_uncached(@gemspec) }.
31
- to raise_error(Bundler::GemspecError)
31
+ expect { subject }.to raise_error(Bundler::GemspecError)
32
32
 
33
- YAML::ENGINE.yamler = orig_yamler
33
+ YAML::ENGINE.yamler = orig_yamler
34
+ end
34
35
  end
35
- end
36
36
 
37
- context "with Psych as YAML::Engine" do
38
- it "raises a GemspecError after YAML load throws Psych::SyntaxError" do
39
- orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
37
+ context "with Psych as YAML::Engine" do
38
+ it "raises a GemspecError after YAML load throws Psych::SyntaxError" do
39
+ orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
40
40
 
41
- expect { Bundler.load_gemspec_uncached(@gemspec) }.
42
- to raise_error(Bundler::GemspecError)
41
+ expect { subject }.to raise_error(Bundler::GemspecError)
43
42
 
44
- YAML::ENGINE.yamler = orig_yamler
43
+ YAML::ENGINE.yamler = orig_yamler
44
+ end
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
- it "can load a gemspec with unicode characters with default ruby encoding" do
50
- # spec_helper forces the external encoding to UTF-8 but that's not the
51
- # ruby default.
52
- encoding = nil
53
-
54
- if defined?(Encoding)
55
- encoding = Encoding.default_external
56
- Encoding.default_external = "ASCII"
57
- end
49
+ context "with correct YAML file" do
50
+ it "can load a gemspec with unicode characters with default ruby encoding" do
51
+ # spec_helper forces the external encoding to UTF-8 but that's not the
52
+ # ruby default.
53
+ if defined?(Encoding)
54
+ encoding = Encoding.default_external
55
+ Encoding.default_external = "ASCII"
56
+ end
58
57
 
59
- File.open(tmp("test.gemspec"), "wb") do |file|
60
- file.puts <<-G.gsub(/^\s+/, '')
61
- # -*- encoding: utf-8 -*-
62
- Gem::Specification.new do |gem|
63
- gem.author = "André the Giant"
64
- end
65
- G
66
- end
58
+ File.open(app_gemspec_path, "wb") do |file|
59
+ file.puts <<-GEMSPEC.gsub(/^\s+/, '')
60
+ # -*- encoding: utf-8 -*-
61
+ Gem::Specification.new do |gem|
62
+ gem.author = "André the Giant"
63
+ end
64
+ GEMSPEC
65
+ end
67
66
 
68
- gemspec = Bundler.load_gemspec_uncached(tmp("test.gemspec"))
69
- expect(gemspec.author).to eq("André the Giant")
67
+ expect(subject.author).to eq("André the Giant")
70
68
 
71
- Encoding.default_external = encoding if defined?(Encoding)
69
+ Encoding.default_external = encoding if defined?(Encoding)
70
+ end
72
71
  end
73
72
 
74
73
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  describe "bundle executable" do
5
4
  it "returns non-zero exit status when passed unrecognized options" do
6
5
  bundle '--invalid_argument', :exitstatus => true
@@ -3,23 +3,19 @@ require 'bundler/definition'
3
3
 
4
4
  describe Bundler::Definition do
5
5
  before do
6
- Bundler.stub(:settings){ Bundler::Settings.new(".") }
6
+ allow(Bundler).to receive(:settings){ Bundler::Settings.new(".") }
7
7
  end
8
8
 
9
9
  describe "#lock" do
10
10
  context "when it's not possible to write to the file" do
11
11
  subject{ Bundler::Definition.new(nil, [], [], []) }
12
12
 
13
- before do
14
- File.should_receive(:open).with("Gemfile.lock", "wb").
15
- and_raise(Errno::EACCES)
16
- end
17
-
18
13
  it "raises an InstallError with explanation" do
14
+ expect(File).to receive(:open).with("Gemfile.lock", "wb").
15
+ and_raise(Errno::EACCES)
19
16
  expect{ subject.lock("Gemfile.lock") }.
20
17
  to raise_error(Bundler::InstallError)
21
18
  end
22
19
  end
23
20
  end
24
-
25
21
  end
@@ -3,38 +3,60 @@ require 'spec_helper'
3
3
  describe Bundler::Dsl do
4
4
  before do
5
5
  @rubygems = double("rubygems")
6
- Bundler::Source::Rubygems.stub(:new){ @rubygems }
6
+ allow(Bundler::Source::Rubygems).to receive(:new){ @rubygems }
7
7
  end
8
8
 
9
- describe "#_normalize_options" do
10
- it "converts :github to :git" do
11
- subject.gem("sparks", :github => "indirect/sparks")
12
- github_uri = "git://github.com/indirect/sparks.git"
13
- expect(subject.dependencies.first.source.uri).to eq(github_uri)
9
+ describe "#register_host" do
10
+ it "registers custom hosts" do
11
+ subject.git_source(:example){ |repo_name| "git@git.example.com:#{repo_name}.git" }
12
+ subject.git_source(:foobar){ |repo_name| "git@foobar.com:#{repo_name}.git" }
13
+ subject.gem("dobry-pies", :example => "strzalek/dobry-pies")
14
+ example_uri = "git@git.example.com:strzalek/dobry-pies.git"
15
+ expect(subject.dependencies.first.source.uri).to eq(example_uri)
14
16
  end
15
17
 
16
- it "converts numeric :gist to :git" do
17
- subject.gem("not-really-a-gem", :gist => 2859988)
18
- github_uri = "https://gist.github.com/2859988.git"
19
- expect(subject.dependencies.first.source.uri).to eq(github_uri)
18
+ it "raises expection on invalid hostname" do
19
+ expect {
20
+ subject.git_source(:group){ |repo_name| "git@git.example.com:#{repo_name}.git" }
21
+ }.to raise_error(Bundler::InvalidOption)
20
22
  end
21
23
 
22
- it "converts :gist to :git" do
23
- subject.gem("not-really-a-gem", :gist => "2859988")
24
- github_uri = "https://gist.github.com/2859988.git"
25
- expect(subject.dependencies.first.source.uri).to eq(github_uri)
24
+ it "expects block passed" do
25
+ expect{ subject.git_source(:example) }.to raise_error(Bundler::InvalidOption)
26
26
  end
27
27
 
28
- it "converts 'rails' to 'rails/rails'" do
29
- subject.gem("rails", :github => "rails")
30
- github_uri = "git://github.com/rails/rails.git"
31
- expect(subject.dependencies.first.source.uri).to eq(github_uri)
28
+ context "default hosts (git, gist)" do
29
+ it "converts :github to :git" do
30
+ subject.gem("sparks", :github => "indirect/sparks")
31
+ github_uri = "git://github.com/indirect/sparks.git"
32
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
33
+ end
34
+
35
+ it "converts numeric :gist to :git" do
36
+ subject.gem("not-really-a-gem", :gist => 2859988)
37
+ github_uri = "https://gist.github.com/2859988.git"
38
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
39
+ end
40
+
41
+ it "converts :gist to :git" do
42
+ subject.gem("not-really-a-gem", :gist => "2859988")
43
+ github_uri = "https://gist.github.com/2859988.git"
44
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
45
+ end
46
+
47
+ it "converts 'rails' to 'rails/rails'" do
48
+ subject.gem("rails", :github => "rails")
49
+ github_uri = "git://github.com/rails/rails.git"
50
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
51
+ end
32
52
  end
33
53
  end
34
54
 
35
55
  describe "#method_missing" do
36
56
  it "raises an error for unknown DSL methods" do
37
- Bundler.should_receive(:read_file).with("Gemfile").and_return("unknown")
57
+ expect(Bundler).to receive(:read_file).with("Gemfile").
58
+ and_return("unknown")
59
+
38
60
  error_msg = "Undefined local variable or method `unknown'" \
39
61
  " for Gemfile\\s+from Gemfile:1"
40
62
  expect { subject.eval_gemfile("Gemfile") }.
@@ -44,7 +66,7 @@ describe Bundler::Dsl do
44
66
 
45
67
  describe "#eval_gemfile" do
46
68
  it "handles syntax errors with a useful message" do
47
- Bundler.should_receive(:read_file).with("Gemfile").and_return("}")
69
+ expect(Bundler).to receive(:read_file).with("Gemfile").and_return("}")
48
70
  expect { subject.eval_gemfile("Gemfile") }.
49
71
  to raise_error(Bundler::GemfileError, /Gemfile syntax error/)
50
72
  end
@@ -54,7 +76,7 @@ describe Bundler::Dsl do
54
76
  it "will raise a Bundler::GemfileError" do
55
77
  gemfile "gem 'foo', :path => /unquoted/string/syntax/error"
56
78
  expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }.
57
- to raise_error(Bundler::GemfileError)
79
+ to raise_error(Bundler::GemfileError, /Gemfile syntax error/)
58
80
  end
59
81
  end
60
82
  end
@@ -2,194 +2,223 @@ require "spec_helper"
2
2
  require 'rake'
3
3
  require 'bundler/gem_helper'
4
4
 
5
- describe "Bundler::GemHelper tasks" do
5
+ describe Bundler::GemHelper do
6
+ let(:app_name) { "test" }
7
+ let(:app_path) { bundled_app app_name }
8
+ let(:app_gemspec_path) { app_path.join("#{app_name}.gemspec") }
9
+
10
+ before(:each) do
11
+ bundle "gem #{app_name}"
12
+ end
13
+
6
14
  context "determining gemspec" do
7
- it "interpolates the name when there is only one gemspec" do
8
- bundle 'gem test'
9
- app = bundled_app("test")
10
- helper = Bundler::GemHelper.new(app.to_s)
11
- expect(helper.gemspec.name).to eq('test')
12
- end
15
+ subject { Bundler::GemHelper.new(app_path) }
13
16
 
14
- it "interpolates the name for a hidden gemspec" do
15
- bundle 'gem test'
16
- app = bundled_app("test")
17
- FileUtils.mv app.join('test.gemspec'), app.join('.gemspec')
18
- helper = Bundler::GemHelper.new(app.to_s)
19
- expect(helper.gemspec.name).to eq('test')
20
- end
17
+ context "fails" do
18
+ it "when there is no gemspec" do
19
+ FileUtils.rm app_gemspec_path
20
+ expect { subject }.to raise_error(/Unable to determine name/)
21
+ end
21
22
 
22
- it "should fail when there is no gemspec" do
23
- bundle 'gem test'
24
- app = bundled_app("test")
25
- FileUtils.rm(File.join(app.to_s, 'test.gemspec'))
26
- expect { Bundler::GemHelper.new(app.to_s) }.to raise_error(/Unable to determine name/)
23
+ it "when there are two gemspecs and the name isn't specified" do
24
+ FileUtils.touch app_path.join("#{app_name}-2.gemspec")
25
+ expect { subject }.to raise_error(/Unable to determine name/)
26
+ end
27
27
  end
28
28
 
29
- it "should fail when there are two gemspecs and the name isn't specified" do
30
- bundle 'gem test'
31
- app = bundled_app("test")
32
- File.open(File.join(app.to_s, 'test2.gemspec'), 'w') {|f| f << ''}
33
- expect { Bundler::GemHelper.new(app.to_s) }.to raise_error(/Unable to determine name/)
29
+ context "interpolates the name" do
30
+ it "when there is only one gemspec" do
31
+ expect(subject.gemspec.name).to eq(app_name)
32
+ end
33
+
34
+ it "for a hidden gemspec" do
35
+ FileUtils.mv app_gemspec_path, app_path.join(".gemspec")
36
+ expect(subject.gemspec.name).to eq(app_name)
37
+ end
34
38
  end
35
39
 
36
- it "handles namespaces and converting to CamelCase" do
37
- bundle 'gem test-foo_bar'
38
- lib = bundled_app('test-foo_bar').join('lib/test/foo_bar.rb').read
39
- expect(lib).to include("module Test")
40
+ it "handles namespaces and converts them to CamelCase" do
41
+ bundle "gem #{app_name}-foo_bar"
42
+ app_path = bundled_app "#{app_name}-foo_bar"
43
+
44
+ lib = app_path.join("lib/#{app_name}/foo_bar.rb").read
45
+ expect(lib).to include("module #{app_name.capitalize}")
40
46
  expect(lib).to include("module FooBar")
41
47
  end
42
48
  end
43
49
 
44
50
  context "gem management" do
45
51
  def mock_confirm_message(message)
46
- Bundler.ui.should_receive(:confirm).with(message)
52
+ expect(Bundler.ui).to receive(:confirm).with(message)
47
53
  end
48
54
 
49
- def mock_build_message
50
- mock_confirm_message "test 0.0.1 built to pkg/test-0.0.1.gem."
55
+ def mock_build_message(name, version)
56
+ message = "#{name} #{version} built to pkg/#{name}-#{version}.gem."
57
+ mock_confirm_message message
51
58
  end
52
59
 
60
+ subject! { Bundler::GemHelper.new(app_path) }
61
+ let(:app_version) { "0.0.1" }
62
+ let(:app_gem_dir) { app_path.join("pkg") }
63
+ let(:app_gem_path) { app_gem_dir.join("#{app_name}-#{app_version}.gem") }
64
+ let(:app_gemspec_content) { File.read(app_gemspec_path) }
65
+
53
66
  before(:each) do
54
- bundle 'gem test'
55
- @app = bundled_app("test")
56
- @gemspec = File.read("#{@app.to_s}/test.gemspec")
57
- File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec.gsub('TODO: ', '') }
58
- @helper = Bundler::GemHelper.new(@app.to_s)
67
+ content = app_gemspec_content.gsub("TODO: ", "")
68
+ File.open(app_gemspec_path, "w") { |file| file << content }
59
69
  end
60
70
 
61
71
  it "uses a shell UI for output" do
62
72
  expect(Bundler.ui).to be_a(Bundler::UI::Shell)
63
73
  end
64
74
 
65
- describe "install_tasks" do
75
+ describe "#install" do
76
+ let!(:rake_application) { Rake.application }
77
+
66
78
  before(:each) do
67
- @saved, Rake.application = Rake.application, Rake::Application.new
79
+ Rake.application = Rake::Application.new
68
80
  end
69
81
 
70
82
  after(:each) do
71
- Rake.application = @saved
83
+ Rake.application = rake_application
72
84
  end
73
85
 
74
- it "defines Rake tasks" do
75
- names = %w[build install release]
76
-
77
- names.each { |name|
78
- expect { Rake.application[name] }.to raise_error(/Don't know how to build task/)
79
- }
86
+ context "defines Rake tasks" do
87
+ let(:task_names) { %w[build install release] }
80
88
 
81
- @helper.install
82
-
83
- names.each { |name|
84
- expect { Rake.application[name] }.not_to raise_error
85
- expect(Rake.application[name]).to be_instance_of Rake::Task
86
- }
87
- end
89
+ context "before installation" do
90
+ it "raises an error with appropriate message" do
91
+ task_names.each do |name|
92
+ expect { Rake.application[name] }.
93
+ to raise_error("Don't know how to build task '#{name}'")
94
+ end
95
+ end
96
+ end
88
97
 
89
- it "provides a way to access the gemspec object" do
90
- @helper.install
91
- expect(Bundler::GemHelper.gemspec.name).to eq('test')
98
+ context "after installation" do
99
+ before do
100
+ subject.install
101
+ end
102
+
103
+ it "adds Rake tasks successfully" do
104
+ task_names.each do |name|
105
+ expect { Rake.application[name] }.not_to raise_error
106
+ expect(Rake.application[name]).to be_instance_of Rake::Task
107
+ end
108
+ end
109
+
110
+ it "provides a way to access the gemspec object" do
111
+ expect(subject.gemspec.name).to eq(app_name)
112
+ end
113
+ end
92
114
  end
93
115
  end
94
116
 
95
- describe "build" do
96
- it "builds" do
97
- mock_build_message
98
- @helper.build_gem
99
- expect(bundled_app('test/pkg/test-0.0.1.gem')).to exist
117
+ describe "#build_gem" do
118
+ context "when build failed" do
119
+ it "raises an error with appropriate message" do
120
+ # break the gemspec by adding back the TODOs
121
+ File.open(app_gemspec_path, "w"){ |file| file << app_gemspec_content }
122
+ expect { subject.build_gem }.to raise_error(/TODO/)
123
+ end
100
124
  end
101
125
 
102
- it "raises an appropriate error when the build fails" do
103
- # break the gemspec by adding back the TODOs...
104
- File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec }
105
- expect { @helper.build_gem }.to raise_error(/TODO/)
126
+ context "when build was successful" do
127
+ it "creates .gem file" do
128
+ mock_build_message app_name, app_version
129
+ subject.build_gem
130
+ expect(app_gem_path).to exist
131
+ end
106
132
  end
107
133
  end
108
134
 
109
- describe "install" do
110
- it "installs" do
111
- mock_build_message
112
- mock_confirm_message "test (0.0.1) installed."
113
- @helper.install_gem
114
- expect(bundled_app('test/pkg/test-0.0.1.gem')).to exist
115
- expect(%x{gem list}).to include("test (0.0.1)")
135
+ describe "#install_gem" do
136
+ context "when installation was successful" do
137
+ it "gem is installed" do
138
+ mock_build_message app_name, app_version
139
+ mock_confirm_message "#{app_name} (#{app_version}) installed."
140
+ subject.install_gem
141
+ expect(app_gem_path).to exist
142
+ expect(`gem list`).to include("#{app_name} (#{app_version})")
143
+ end
116
144
  end
117
145
 
118
- it "raises an appropriate error when the install fails" do
119
- @helper.should_receive(:build_gem) do
120
- # write an invalid gem file, so we can simulate install failure...
121
- FileUtils.mkdir_p(File.join(@app.to_s, 'pkg'))
122
- path = "#{@app.to_s}/pkg/test-0.0.1.gem"
123
- File.open(path, 'w'){|f| f << "not actually a gem"}
124
- path
146
+ context "when installation fails" do
147
+ it "raises an error with appropriate message" do
148
+ # create empty gem file in order to simulate install failure
149
+ allow(subject).to receive(:build_gem) do
150
+ FileUtils.mkdir_p(app_gem_dir)
151
+ FileUtils.touch app_gem_path
152
+ app_gem_path
153
+ end
154
+ expect { subject.install_gem }.to raise_error(/Couldn't install gem/)
125
155
  end
126
- expect { @helper.install_gem }.to raise_error
127
156
  end
128
157
  end
129
158
 
130
- describe "release" do
159
+ describe "#release_gem" do
131
160
  before do
132
- Dir.chdir(@app) do
161
+ Dir.chdir(app_path) do
133
162
  `git init`
134
163
  `git config user.email "you@example.com"`
135
164
  `git config user.name "name"`
136
165
  end
137
166
  end
138
167
 
139
- it "shouldn't push if there are unstaged files" do
140
- expect { @helper.release_gem }.to raise_error(/files that need to be committed/)
141
- end
142
-
143
- it "shouldn't push if there are uncommitted files" do
144
- %x{cd test; git add .}
145
- expect { @helper.release_gem }.to raise_error(/files that need to be committed/)
146
- end
168
+ context "fails" do
169
+ it "when there are unstaged files" do
170
+ expect { subject.release_gem }.
171
+ to raise_error("There are files that need to be committed first.")
172
+ end
147
173
 
148
- it "raises an appropriate error if there is no git remote" do
149
- Bundler.ui.stub(:confirm => nil, :error => nil) # silence messages
174
+ it "when there are uncommitted files" do
175
+ Dir.chdir(app_path) { `git add .` }
176
+ expect { subject.release_gem }.
177
+ to raise_error("There are files that need to be committed first.")
178
+ end
150
179
 
151
- Dir.chdir(gem_repo1) { `git init --bare` }
152
- Dir.chdir(@app) { `git commit -a -m "initial commit"` }
180
+ it "when there is no git remote" do
181
+ # silence messages
182
+ allow(Bundler.ui).to receive(:confirm)
183
+ allow(Bundler.ui).to receive(:error)
153
184
 
154
- expect { @helper.release_gem }.to raise_error
185
+ Dir.chdir(app_path) { `git commit -a -m "initial commit"` }
186
+ expect { subject.release_gem }.to raise_error
187
+ end
155
188
  end
156
189
 
157
- it "releases" do
158
- mock_build_message
159
- mock_confirm_message(/Tagged v0.0.1/)
160
- mock_confirm_message("Pushed git commits and tags.")
190
+ context "succeeds" do
191
+ before do
192
+ Dir.chdir(gem_repo1) { `git init --bare` }
193
+ Dir.chdir(app_path) do
194
+ `git remote add origin file://#{gem_repo1}`
195
+ `git commit -a -m "initial commit"`
196
+ end
197
+ end
198
+
199
+ it "on releasing" do
200
+ mock_build_message app_name, app_version
201
+ mock_confirm_message "Tagged v#{app_version}."
202
+ mock_confirm_message "Pushed git commits and tags."
203
+ expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s)
161
204
 
162
- @helper.should_receive(:rubygem_push).with(bundled_app('test/pkg/test-0.0.1.gem').to_s)
205
+ Dir.chdir(app_path) { sys_exec("git push origin master", true) }
163
206
 
164
- Dir.chdir(gem_repo1) { `git init --bare` }
165
- Dir.chdir(@app) do
166
- `git remote add origin file://#{gem_repo1}`
167
- `git commit -a -m "initial commit"`
168
- sys_exec("git push origin master", true)
169
- `git commit -a -m "another commit"`
207
+ subject.release_gem
170
208
  end
171
- @helper.release_gem
172
- end
173
209
 
174
- it "releases even if tag already exists" do
175
- mock_build_message
176
- mock_confirm_message("Tag v0.0.1 has already been created.")
210
+ it "even if tag already exists" do
211
+ mock_build_message app_name, app_version
212
+ mock_confirm_message "Tag v#{app_version} has already been created."
213
+ expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s)
177
214
 
178
- @helper.should_receive(:rubygem_push).with(bundled_app('test/pkg/test-0.0.1.gem').to_s)
215
+ Dir.chdir(app_path) do
216
+ `git tag -a -m \"Version #{app_version}\" v#{app_version}`
217
+ end
179
218
 
180
- Dir.chdir(gem_repo1) {
181
- `git init --bare`
182
- }
183
- Dir.chdir(@app) {
184
- `git init`
185
- `git config user.email "you@example.com"`
186
- `git config user.name "name"`
187
- `git commit -a -m "another commit"`
188
- `git tag -a -m \"Version 0.0.1\" v0.0.1`
189
- }
190
- @helper.release_gem
219
+ subject.release_gem
220
+ end
191
221
  end
192
-
193
222
  end
194
223
  end
195
224
  end