mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 11:23:42 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
63 lines
1.5 KiB
Ruby
63 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rspec/core/formatters/base_text_formatter"
|
|
require "parallel_tests/rspec/logger_base"
|
|
|
|
module Autospec; end
|
|
|
|
class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
|
|
RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
|
|
|
|
RSPEC_RESULT = "./tmp/rspec_result"
|
|
|
|
def initialize(output)
|
|
super
|
|
FileUtils.mkdir_p("tmp") unless Dir.exists?("tmp")
|
|
end
|
|
|
|
def start(example_count)
|
|
super
|
|
File.delete(RSPEC_RESULT) if File.exists?(RSPEC_RESULT)
|
|
@fail_file = File.open(RSPEC_RESULT, "w")
|
|
end
|
|
|
|
def example_passed(_notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('.', :success)
|
|
end
|
|
|
|
def example_pending(_notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('*', :pending)
|
|
end
|
|
|
|
def example_failed(notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
|
|
@fail_file.puts(notification.example.metadata[:location] + " ")
|
|
@fail_file.flush
|
|
end
|
|
|
|
def start_dump(notification)
|
|
output.puts
|
|
end
|
|
|
|
def close(filename)
|
|
@fail_file.close
|
|
super(filename)
|
|
end
|
|
|
|
end
|
|
|
|
class Autospec::ParallelFormatter < ParallelTests::RSpec::LoggerBase
|
|
RSpec::Core::Formatters.register self, :example_failed
|
|
|
|
def message(*args);end
|
|
def dump_failures(*args);end
|
|
def dump_summary(*args);end
|
|
def dump_pending(*args);end
|
|
def seed(*args);end
|
|
|
|
def example_failed(notification)
|
|
output.puts notification.example.metadata[:location] + " "
|
|
end
|
|
end
|