lib/magic_test/support.rb in magic_test-0.0.7 vs lib/magic_test/support.rb in magic_test-0.0.9

- old
+ new

@@ -74,20 +74,32 @@ # TODO we need to add more robust instructions for this. raise "You need to configure this test (or your test suite) to run in a real browser (Chrome, Firefox, etc.) in order for Magic Test to work. It also needs to run in non-headless mode if `ENV['MAGIC_TEST'].present?`" end def magic_test + return unless ENV["MAGIC_TEST"].present? empty_cache @test_lines_written = 0 begin - # 👋 This isn't helpful context. Type `up` and hit enter to see where you really are. + magic_test_pry_hook binding.pry rescue retry end end private + + def magic_test_pry_hook + Pry.hooks.add_hook(:before_session, "magic_test") do |output, binding, pry| + Pry.hooks.delete_hook(:before_session, 'magic_test') + magic_test_file_index = pry.backtrace.index{|line| line.include?(__FILE__)} + # walk up backtrace until finding the original caller + until pry.backtrace[magic_test_file_index + 1].include?(pry.last_file) do + pry.run_command('up') + end + end + end def get_last history_lines = Readline::HISTORY.to_a.last(20) i = 2 last = history_lines.last(2).first