module Teaspoon::Engine::ExceptionHandling

Public Class Methods

add_rails_handling() click to toggle source
# File lib/teaspoon/engine.rb, line 72
def self.add_rails_handling
  return unless using_phantomjs?

  # debugging should be off to display errors in the suite_controller
  # Rails.application.config.assets.debug = false

  # we want rails to display exceptions
  Rails.application.config.action_dispatch.show_exceptions = true

  # override the render exception method in ActionDispatch to raise a javascript exception
  render_exceptions_with_javascript
end

Private Class Methods

render_exceptions_with_javascript() click to toggle source
# File lib/teaspoon/engine.rb, line 91
def self.render_exceptions_with_javascript
  ActionDispatch::DebugExceptions.class_eval do
    def render_exception(_env, exception)
      message = "#{exception.class.name}: #{exception.message}"
      body = "<script>throw Error(#{[message, exception.backtrace].join("\n").inspect})</script>"
      [200, { "Content-Type" => "text/html;", "Content-Length" => body.bytesize.to_s }, [body]]
    end
  end
end
using_phantomjs?() click to toggle source
# File lib/teaspoon/engine.rb, line 87
def self.using_phantomjs?
  Teaspoon::Driver.matches?(Teaspoon.configuration.driver, :phantomjs)
end

Private Instance Methods

render_exception(_env, exception) click to toggle source
# File lib/teaspoon/engine.rb, line 93
def render_exception(_env, exception)
  message = "#{exception.class.name}: #{exception.message}"
  body = "<script>throw Error(#{[message, exception.backtrace].join("\n").inspect})</script>"
  [200, { "Content-Type" => "text/html;", "Content-Length" => body.bytesize.to_s }, [body]]
end