Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created November 2, 2011 16:44
Show Gist options
  • Save betawaffle/1334162 to your computer and use it in GitHub Desktop.
Save betawaffle/1334162 to your computer and use it in GitHub Desktop.
I just stuck that in the spec_helper.rb.
begin
require 'pry'
rescue LoadError
class Object
def pry
# Do Nothing.
end
end
end
# ...
if defined? Pry
class Binding
def fake(file, line)
orig = method(:eval)
define_singleton_method(:eval) do |s, f = nil, l = nil|
orig.call(s, f || file.to_s, l || line.to_i)
end
self
end
end
class RSpec::Core::Example
def set_exception_with_pry(e)
set_exception_without_pry(e)
file, line, _ = e.backtrace.find { |f| f.match /^#{Rails.root}/ }.split(':', 3)
Pry.binding_for(@example_group_instance).fake(file, line).pry
end
alias_method :set_exception_without_pry, :set_exception
alias_method :set_exception, :set_exception_with_pry
end
end
@akasper
Copy link

akasper commented Nov 2, 2011

Any way you can make it a flag? So I could do:

bundle exec rspec spec/lib --pry

or somesuch?

@betawaffle
Copy link
Author

I'm not at that stage yet.

@betawaffle
Copy link
Author

Spork complicates this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment