diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a524e1b3e9d..8115ac0727e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,17 +46,14 @@ module WebMock::API end end +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + # nuke the db (say, if `rake db:migrate RAILS_ENV=test` created records), # and then ensure people aren't creating records outside the rspec # lifecycle, e.g. inside a describe/context block rather than a # let/before/example -require_relative 'support/blank_slate_protection' BlankSlateProtection.install! -require_relative 'support/discourage_slow_specs' - -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } - ActionView::TestCase::TestController.view_paths = ApplicationController.view_paths # this makes sure that a broken transaction becomes functional again diff --git a/spec/support/debuggable_timeout.rb b/spec/support/debuggable_timeout.rb new file mode 100644 index 00000000000..f2e98f14dc8 --- /dev/null +++ b/spec/support/debuggable_timeout.rb @@ -0,0 +1,20 @@ +# disable timeouts (in particular the spec one) once we start a pry session +# +# note: there's not really a great way to detect when the session is done, +# and making this only disable the spec timeout would be a lot more code. +# so once you start up pry, all timeouts are disabled, but ¯\_(ツ)_/¯ + +Timeout.singleton_class.prepend(Module.new { + def sleep(*) + result = super + in_debugger_land = defined?(Pry) && Pry::InputLock.input_locks.any? + + if in_debugger_land + # abort the timeout thread, otherwise it will raise in the main + # thread once sleep returns + Thread.current.kill + end + + result + end +})