diff --git a/bundler/lib/bundler/cli/console.rb b/bundler/lib/bundler/cli/console.rb index 2ba5e69bde0e..f6389e8ea004 100644 --- a/bundler/lib/bundler/cli/console.rb +++ b/bundler/lib/bundler/cli/console.rb @@ -20,9 +20,14 @@ def get_console(name) require name get_constant(name) rescue LoadError - Bundler.ui.error "Couldn't load console #{name}, falling back to irb" - require "irb" - get_constant("irb") + if name == "irb" + Bundler.ui.error "#{name} is not available" + exit 1 + else + Bundler.ui.error "Couldn't load console #{name}, falling back to irb" + name = "irb" + retry + end end def get_constant(name) @@ -32,9 +37,6 @@ def get_constant(name) "irb" => :IRB, }[name] Object.const_get(const_name) - rescue NameError - Bundler.ui.error "Could not find constant #{const_name}" - exit 1 end end end diff --git a/bundler/spec/commands/console_spec.rb b/bundler/spec/commands/console_spec.rb index 9fc738613716..dd7461ced422 100644 --- a/bundler/spec/commands/console_spec.rb +++ b/bundler/spec/commands/console_spec.rb @@ -113,6 +113,17 @@ def __pry__ expect(out).to include("(irb)") end + it "does not try IRB twice if no console is configured and IRB is not available" do + create_file("irb.rb", "raise LoadError, 'irb is not available'") + + bundle("console", env: { "RUBYOPT" => "-I#{bundled_app} #{ENV["RUBYOPT"]}" }, raise_on_error: false) do |input, _, _| + input.puts("puts ACTIVESUPPORT") + input.puts("exit") + end + expect(err).not_to include("falling back to irb") + expect(err).to include("irb is not available") + end + it "doesn't load any other groups" do bundle "console" do |input, _, _| input.puts("puts ACTIVESUPPORT")