Repository: rails/rails
File: activesupport/lib/active_support/continuous_integration.rb (Ruby)

Code before:
    end

    # Echo text to the terminal in the color corresponding to the type of the text.
    #
    # Examples:
    #
    #   echo "This is going to be green!", type: :success
    #   echo "This is going to be red!", type: :error
    #
    # See ActiveSupport::ContinuousIntegration::COLORS for a complete list of options.
    def echo(text, type:)
      puts colorize(text, type)
    end

    # :nodoc:
    def report(title, &block)
      Signal.trap("INT") { abort colorize(:error, "\n❌ #{title} interrupted") }

      ci = self.class.new
      elapsed = timing { ci.instance_eval(&block) }

      if ci.success?
        echo "\n✅ #{title} passed in #{elapsed}", type: :success
      else
        echo "\n❌ #{title} failed in #{elapsed}", type: :error
        ci.failure_summary(title)
      end

      results.concat ci.results
    ensure
      Signal.trap("INT", "-")
    end

    # :nodoc:
    def failure_summary(title)
      return if success? || results.size < 2

      results.each do |success, title|
        unless success
          echo "   ↳ #{title} failed", type: :error
        end
      end
    end

    private
      def timing
        started_at = Time.now.to_f
        yield
        min, sec = (Time.now.to_f - started_at).divmod(60)
        "#{"#{min}m" if min > 0}%.2fs" % sec
      end

Review comment (bug):
Actually, I would inline the production of the output here like this:

```ruby
def report(title, &block)
  Signal.trap("INT") { abort colorize(:error, "\n❌ #{title} interrupted") }

  ci = self.class.new
  elapsed = timing { ci.instance_eval(&block) }

  if ci.success?
    echo "\n✅ #{title} passed in #{elapsed}", type: :success
  else
    echo "\n❌ #{title} failed in #{elapsed}", type: :error

    failures.each do |title|
      echo "   ↳ #{title} failed", type: :error
    end
  end

  results.concat ci.results
ensure
  Signal.trap("INT", "-")
end

def failures
  results.select(&:first)
end
```

Code after:
    end

    # Echo text to the terminal in the color corresponding to the type of the text.
    #
    # Examples:
    #
    #   echo "This is going to be green!", type: :success
    #   echo "This is going to be red!", type: :error
    #
    # See ActiveSupport::ContinuousIntegration::COLORS for a complete list of options.
    def echo(text, type:)
      puts colorize(text, type)
    end

    # :nodoc:
    def report(title, &block)
      Signal.trap("INT") { abort colorize(:error, "\n❌ #{title} interrupted") }

      ci = self.class.new
      elapsed = timing { ci.instance_eval(&block) }

      if ci.success?
        echo "\n✅ #{title} passed in #{elapsed}", type: :success
      else
        echo "\n❌ #{title} failed in #{elapsed}", type: :error

        if ci.multiple_results?
          ci.failures.each do |success, title|
            unless success
              echo "   ↳ #{title} failed", type: :error
            end
          end
        end
      end

      results.concat ci.results
    ensure
      Signal.trap("INT", "-")
    end

    # :nodoc:
    def failures
      results.reject(&:first)
    end

    # :nodoc:
    def multiple_results?
      results.size > 1
    end

    private