ConradIrwin / pry-rescue

Start a pry session whenever something goes wrong.
MIT License
852 stars 49 forks source link

rescue with (spring-generated) bin/rspec binstub #86

Closed aeonaut closed 3 years ago

aeonaut commented 9 years ago

I use Spring and thus have a Spring-generated bin/rspec stub. I have ./bin at the front of my path, so normally just a normal rspec path/to/file uses this binstub. Problem is, Rescue doesn't work correctly with the binstub. Here's what happens:

$ time rescue bin/rspec path/to/file
Finished in 4.97 seconds (files took 0.87762 seconds to load)
1 example, 0 failures

real    0m6.961s
user    0m0.613s
sys     0m0.171s

$ time rescue rspec path/to/file
Finished in 5.06 seconds (files took 5.12 seconds to load)
1 example, 0 failures

real    0m10.683s
user    0m6.601s
sys     0m2.059s

Option 1 uses the Spring binstub and takes 7 seconds; Option 2 apparently does not use the binstub, because it takes 10+ seconds. Option 1 looks pretty good -- except that Rescue doesn't actually work. The test fails without opening a pry session. (Rescue works as expected in Option 2).

So at the moment doesn't look like I can use both Rescue and Spring together. Ideas?

joallard commented 8 years ago

Just went on a fact-finding mission about this.

If we use the bundled Rescue and binstubs, rescue rspec won't use bin/rspec. That's because Bundler, before loading Rescue, adds components to the path re-prioritizing the installed rspec over the bin/rspec. So we get the non-springified Rspec.

If we use rescue bin/rspec, the case in bin/rescue, which uses a regex for /^rspec/, won't run. Meaning Rescue isn't activated.

Ideally we would detect if we are using Spring/a binstub and somehow run that instead of the non-spring rspec

joallard commented 8 years ago

I looked into making a spring command for Rescue, but it appears even if we load spring and call rspec, Spring won't be loaded for the nested command. (Feel free to double check this, I didn't invest the time in understanding how Spring worked exactly)

The monkeypatch that appears to be working is to let /bin/rescue detect when rspec is ran even prefixed by bin/ or other. It's a bit ugly, but appears to be working:

diff --git a/bin/rescue b/bin/rescue
index b9856d3..2449b4e 100755
--- a/bin/rescue
+++ b/bin/rescue
@@ -34,12 +34,15 @@ when '-i'
 when /\A-/
   puts USAGE
   exit
-when 'rails'
-  ENV['PRY_RESCUE_RAILS'] = 'true'
-  exec(*ARGV)
-when /^re?spec|rake$/
-  ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} -r pry-rescue/rspec"
-  exec(*ARGV)
+else
+  case File.basename(ARGV[0] || "")
+  when 'rails'
+    ENV['PRY_RESCUE_RAILS'] = 'true'
+    exec(*ARGV)
+  when /^re?spec|rake$/
+    ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} -r pry-rescue/rspec"
+    exec(*ARGV)
+  end
 end
catmando commented 8 years ago

Having the same problem, but I am not having any luck working around it per joallards patch

I installed pry-rescue from https://github.com/joallard/pry-rescue.git but I still see the same issue i.e. if I use bin/rspec spring works, but rescue does not.

joallard commented 8 years ago

@catmando The good stuff is on the bin-rspec branch

TylerRick commented 5 years ago

Hmm, I'm not having any problems with using the spring binstub with rescue. At least now that I have pry-stack_explorer installed (#98, but that's a different symptom than you're describing here)...

Is this still a problem for you with current versions of these gems, or can this issue be closed?