diff options
Diffstat (limited to 'spec/bundler/bundler/friendly_errors_spec.rb')
-rw-r--r-- | spec/bundler/bundler/friendly_errors_spec.rb | 83 |
1 files changed, 22 insertions, 61 deletions
diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index dc9d539a30..747d774b25 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -6,59 +6,26 @@ require "cgi" RSpec.describe Bundler, "friendly errors" do context "with invalid YAML in .gemrc" do - context "with the old ~/.gemrc" do - before do - File.open(home(".gemrc"), "w") do |f| - f.write "invalid: yaml: hah" - end - end - - after do - FileUtils.rm(home(".gemrc")) - end - - it "reports a relevant friendly error message" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - - bundle :install, :env => { "DEBUG" => "true" } - - expect(err).to include("Failed to load #{home(".gemrc")}") - expect(exitstatus).to eq(0) if exitstatus + before do + File.open(home(".gemrc"), "w") do |f| + f.write "invalid: yaml: hah" end end - context "with XDG_CONFIG_HOME" do - let(:config_home) { File.dirname(Gem.configuration.config_file_name) } - - before do - FileUtils.mkdir_p config_home - File.open(Gem.configuration.config_file_name, "w") do |f| - f.write "invalid: yaml: hah" - end - end - - after do - FileUtils.rm(Gem.configuration.config_file_name) - end + after do + FileUtils.rm(home(".gemrc")) + end - it "reports a relevant friendly error message" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G + it "reports a relevant friendly error message" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G - bundle :install, :env => { "DEBUG" => "true" } + bundle :install, :env => { "DEBUG" => "true" } - if Gem::VERSION >= "3.2.0.pre.1" - expect(err).to include("Failed to load #{File.join(config_home, "gemrc")}") - else - expect(err).to include("Failed to load #{home(".gemrc")}") - end - expect(exitstatus).to eq(0) if exitstatus - end + expect(err).to include("Failed to load #{home(".gemrc")}") + expect(exitstatus).to eq(0) if exitstatus end end @@ -148,18 +115,12 @@ RSpec.describe Bundler, "friendly errors" do context "LoadError" do let(:error) { LoadError.new("cannot load such file -- openssl") } - it "Bundler.ui receive error" do - expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL.") - Bundler::FriendlyErrors.log_error(error) - end - - it "Bundler.ui receive warn" do - expect(Bundler.ui).to receive(:warn).with(any_args, :wrap => true) - Bundler::FriendlyErrors.log_error(error) + before do + allow(error).to receive(:backtrace).and_return(["backtrace"]) end - it "Bundler.ui receive trace" do - expect(Bundler.ui).to receive(:trace).with(error) + it "Bundler.ui receive error" do + expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL. LoadError: cannot load such file -- openssl\nbacktrace") Bundler::FriendlyErrors.log_error(error) end end @@ -254,7 +215,7 @@ RSpec.describe Bundler, "friendly errors" do it "generates a search URL for the exception message" do exception = Exception.new("Exception message") - expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=Exception+message&type=Issues") + expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=Exception+message&type=Issues") end it "generates a search URL for only the first line of a multi-line exception message" do @@ -263,7 +224,7 @@ First line of the exception message Second line of the exception message END - expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=First+line+of+the+exception+message&type=Issues") + expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=First+line+of+the+exception+message&type=Issues") end it "generates the url without colons" do @@ -272,7 +233,7 @@ Exception ::: with ::: colons ::: END issues_url = Bundler::FriendlyErrors.issues_url(exception) expect(issues_url).not_to include("%3A") - expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues") + expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues") end it "removes information after - for Errono::EACCES" do @@ -282,7 +243,7 @@ END allow(exception).to receive(:is_a?).with(Errno).and_return(true) issues_url = Bundler::FriendlyErrors.issues_url(exception) expect(issues_url).not_to include("/Users/foo/bar") - expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues") + expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues") end end end |