summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Bùˆnemann <buenemann@louis.info>2015-11-16 20:26:15 +0100
committerFelix Bùˆnemann <buenemann@louis.info>2015-11-16 20:26:15 +0100
commit95d21b224284739e0fd1bf936cc36688e669b377 (patch)
treead34d9bb0531446cf806c6ac5a6d8d627dd2489e
parentf787c664b4645fb44066b140b3b9afee542590c9 (diff)
downloadbundler-95d21b224284739e0fd1bf936cc36688e669b377.tar.gz
Fix bundle console specs
The previous specs only worked by accident, because the error message "Couldn't load pry\nCould not find constant IRB\n" contained both of the strings expected by the assertions. In order to test loading an alternate console without adding a permanent dependency, we can use a fake pry gem that implements the minimum required api.
-rw-r--r--spec/commands/console_spec.rb20
-rw-r--r--spec/support/builders.rb33
2 files changed, 49 insertions, 4 deletions
diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb
index f26fbcdba5..4b1de42e8a 100644
--- a/spec/commands/console_spec.rb
+++ b/spec/commands/console_spec.rb
@@ -18,14 +18,26 @@ describe "bundle console" do
expect(out).to include("0.9.1")
end
+ it "uses IRB as default console" do
+ bundle "console" do |input|
+ input.puts("__method__")
+ input.puts("exit")
+ end
+ expect(out).to include(":irb_binding")
+ end
+
it "starts another REPL if configured as such" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "pry"
+ G
bundle "config console pry"
bundle "console" do |input|
- input.puts("__callee__")
+ input.puts("__method__")
input.puts("exit")
end
- expect(out).to include("pry")
+ expect(out).to include(":__pry__")
end
it "falls back to IRB if the other REPL isn't available" do
@@ -33,10 +45,10 @@ describe "bundle console" do
# make sure pry isn't there
bundle "console" do |input|
- input.puts("__callee__")
+ input.puts("__method__")
input.puts("exit")
end
- expect(out).to include("IRB")
+ expect(out).to include(":irb_binding")
end
it "doesn't load any other groups" do
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index 95b4b6eb59..913263c51d 100644
--- a/spec/support/builders.rb
+++ b/spec/support/builders.rb
@@ -242,6 +242,39 @@ module Spec
end
build_gem "foo"
+
+ # A minimal fake pry console
+ build_gem "pry" do |s|
+ s.write "lib/pry.rb", <<-RUBY
+ class Pry
+ class << self
+ def toplevel_binding
+ unless defined?(@toplevel_binding) && @toplevel_binding
+ TOPLEVEL_BINDING.eval %{
+ def self.__pry__; binding; end
+ Pry.instance_variable_set(:@toplevel_binding, __pry__)
+ class << self; undef __pry__; end
+ }
+ end
+ @toplevel_binding.eval('private')
+ @toplevel_binding
+ end
+
+ def __pry__
+ while line = gets
+ begin
+ puts eval(line, toplevel_binding).inspect.sub(/^"(.*)"$/, '=> \\1')
+ rescue Exception => e
+ puts "\#{e.class}: \#{e.message}"
+ puts e.backtrace.first
+ end
+ end
+ end
+ alias start __pry__
+ end
+ end
+ RUBY
+ end
end
end