Module: RSpec::Signal

Defined in:
lib/rspec/signal.rb,
lib/rspec/signal/group.rb,
lib/rspec/signal/report.rb,
lib/rspec/signal/writer.rb,
lib/rspec/signal/cluster.rb,
lib/rspec/signal/failure.rb,
lib/rspec/signal/grouper.rb,
lib/rspec/signal/message.rb,
lib/rspec/signal/project.rb,
lib/rspec/signal/symptom.rb,
lib/rspec/signal/version.rb,
lib/rspec/signal/redactor.rb,
lib/rspec/signal/symptoms.rb,
lib/rspec/signal/clusterer.rb,
lib/rspec/signal/formatter.rb,
lib/rspec/signal/fingerprint.rb,
lib/rspec/signal/html_summary.rb,
lib/rspec/signal/parallel_run.rb,
lib/rspec/signal/configuration.rb,
lib/rspec/signal/symptoms/route.rb,
lib/rspec/signal/backtrace/frame.rb,
lib/rspec/signal/failure_builder.rb,
lib/rspec/signal/parallel_merger.rb,
lib/rspec/signal/symptoms/record.rb,
lib/rspec/signal/backtrace/parser.rb,
lib/rspec/signal/backtrace/reducer.rb,
lib/rspec/signal/symptoms/selector.rb,
lib/rspec/signal/reporters/markdown.rb,
lib/rspec/signal/symptoms/ruby_error.rb,
lib/rspec/signal/backtrace/classifier.rb,
lib/rspec/signal/symptoms/http_status.rb,
lib/rspec/signal/integrations/capybara.rb,
lib/rspec/signal/reporters/full_output.rb,
lib/rspec/signal/reporters/json_report.rb,
lib/rspec/signal/symptoms/exception_class.rb,
lib/rspec/signal/reporters/related_failures.rb

Overview

Turns noisy RSpec failures into compact, high-signal diagnostic artifacts designed to be handed to an AI coding agent.

Defined Under Namespace

Modules: Backtrace, Clusterer, Grouper, Integrations, ParallelRun, Reporters, Symptoms Classes: Cluster, Configuration, Failure, FailureBuilder, Fingerprint, Formatter, Group, HtmlSummary, Message, ParallelMerger, Project, Redactor, Report, Symptom, Writer

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.auto_installed?Boolean

True when we added the formatter ourselves rather than the user asking for it with --format. Only then do we put RSpec's default formatter back, because only then did we displace it.

Returns:

  • (Boolean)


81
# File 'lib/rspec/signal.rb', line 81

def auto_installed? = !!@auto_installed

.configurationObject



40
41
42
# File 'lib/rspec/signal.rb', line 40

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



44
45
46
47
48
# File 'lib/rspec/signal.rb', line 44

def configure
  yield configuration if block_given?
  configuration.reset_memoized!
  configuration
end

.environmentObject

Versions worth recording in the report header.



111
112
113
114
115
116
117
118
# File 'lib/rspec/signal.rb', line 111

def environment
  versions = { "ruby" => RUBY_VERSION, "rspec" => ::RSpec::Core::Version::STRING }
  versions["rails"] = ::Rails::VERSION::STRING if defined?(::Rails::VERSION::STRING)
  versions["capybara"] = ::Capybara::VERSION if defined?(::Capybara::VERSION)
  versions
rescue StandardError
  { "ruby" => RUBY_VERSION }
end

.install!(rspec_config = ::RSpec.configuration) ⇒ Boolean

Registers the formatter and optional integrations.

Called automatically when you require "rspec/signal" inside an RSpec.configure block or from spec_helper.rb. Safe to call twice.

Returns:

  • (Boolean)

    whether anything was installed



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rspec/signal.rb', line 56

def install!(rspec_config = ::RSpec.configuration)
  return false if @installed

  @installed = true
  return false unless configuration.enabled?

  quiet_mode? # Capture CLI intent before RSpec finishes parsing ARGV.
  loader = rspec_config.formatter_loader
  unless loader.formatters.any?(Formatter)
    rspec_config.add_formatter(Formatter)
    @auto_installed = true
  end

  install_integrations!(rspec_config)
  true
rescue StandardError => e
  warn "rspec-signal: could not install (#{e.class}: #{e.message})"
  false
end

.installed?Boolean

Returns:

  • (Boolean)


76
# File 'lib/rspec/signal.rb', line 76

def installed? = !!@installed

.quiet_mode?Boolean

Explicit formatter selection happens after --require files are loaded, so install! may initially look automatic. Detect the user's intent from the original CLI arguments (or the wrapper's explicit marker) at start time, after RSpec has finished configuring its formatter loader.

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/rspec/signal.rb', line 87

def quiet_mode?
  return true if ENV["RSPEC_SIGNAL_QUIET"] == "1"
  return @quiet_mode_requested if defined?(@quiet_mode_requested)

  @quiet_mode_requested = formatter_arguments.intersect?(["RSpec::Signal::Formatter", "signal"])
end

.reset!Object



121
122
123
124
125
126
# File 'lib/rspec/signal.rb', line 121

def reset!
  @installed = false
  @auto_installed = false
  remove_instance_variable(:@quiet_mode_requested) if defined?(@quiet_mode_requested)
  @configuration = nil
end

.restore_default_formatter!(rspec_config = ::RSpec.configuration) ⇒ Object

Adding any formatter suppresses RSpec's default one. When rspec-signal installed itself the user did not ask for that, so restore normal terminal feedback.



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rspec/signal.rb', line 97

def restore_default_formatter!(rspec_config = ::RSpec.configuration)
  loader = rspec_config.formatter_loader
  return if loader.formatters.any? { |formatter| primary_output_formatter?(formatter) }

  before = loader.formatters.dup
  loader.add(loader.default_formatter, rspec_config.output_stream)
  (loader.formatters - before).each do |formatter|
    formatter.start(::RSpec::Core::Notifications::StartNotification.new(0, 0)) if formatter.respond_to?(:start)
  end
rescue StandardError
  nil
end