module ActionController
  module TestResponseStringOverride
    def to_s
      status, headers, body = to_a
      body = ''.tap { |out| body.each { |s| out << s } }
      "#<#{self.class.name} #{request.method} #{request.fullpath} => " \
        "[#{status}, #{body.inspect}, #{headers.inspect}]>"
    end

    def inspect
      to_s
    end
  end

  RSpec.configure do |config|
    config.before(:suite) do
      TestResponse.send(:include, TestResponseStringOverride)
    end
  end
end

module ActionController
  module TestResponseStringOverride
    def to_s
      status, headers, body = to_a
      body = ''.tap { |out| body.each { |s| out << s } }
      "#<#{self.class.name} #{request.method} #{request.fullpath} => " \
        "[#{status}, #{body.inspect}, #{headers.inspect}]>"
    end

    def inspect
      to_s
    end
  end

  RSpec.configure do |config|
    config.before(:suite) do
      if defined?(TestResponse)
        TestResponse.send(:include, TestResponseStringOverride)
      end
    end
  end
end

Fix bug with TestResponse override outside Rails
Fix bug with TestResponse override outside Rails

When loading spec_helper instead of rails_helpers,
ActionController::TestResponse is not defined.
