Module: RSpec::Risky

Defined in:
lib/rspec/risky.rb,
lib/rspec/risky/verdict.rb,
lib/rspec/risky/version.rb,
lib/rspec/risky/formatter.rb,
lib/rspec/risky/rspec_cli.rb,
lib/rspec/risky/evaluation.rb,
lib/rspec/risky/configuration.rb,
lib/rspec/risky/json_formatter.rb,
lib/rspec/risky/minitest/plugin.rb,
lib/rspec/risky/static_detector.rb,
lib/rspec/risky/probe/fd_capture.rb,
lib/rspec/risky/minitest/reporter.rb,
lib/rspec/risky/probe/output_probe.rb,
lib/rspec/risky/probe/recording_io.rb,
lib/rspec/risky/probe/output_report.rb,
lib/rspec/risky/json_event_formatter.rb,
lib/rspec/risky/minitest/output_capture.rb,
lib/rspec/risky/probe/expectation_probe.rb,
sig/rspec/risky.rbs

Defined Under Namespace

Modules: Evaluation, Minitest, Probe, RSpecCli, Verdict Classes: Configuration, Error, Formatter, JsonEventFormatter, JsonFormatter, RedundantPrintConfig, RiskyExampleError, RuleConfig, RuleResult, StaticDetector, UnknownTestConfig

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationConfiguration

Returns:



31
32
33
# File 'lib/rspec/risky.rb', line 31

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure(rspec_configuration = nil) {|configuration| ... } ⇒ Configuration

Parameters:

  • rspec_configuration (Object) (defaults to: nil)

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:



39
40
41
42
43
44
45
46
# File 'lib/rspec/risky.rb', line 39

def configure(rspec_configuration = nil)
  yield configuration if block_given?

  install!
  integrate!(rspec_configuration || default_rspec_configuration)

  configuration
end

.install!Object



48
49
50
51
52
53
54
55
56
# File 'lib/rspec/risky.rb', line 48

def install!
  return if @installed

  Probe::ExpectationProbe.install
  Probe::OutputProbe.install
  RSpecCli.install

  @installed = true
end

.record_expectation(count = 1) ⇒ void

This method returns an undefined value.

Parameters:

  • count (Integer) (defaults to: 1)


35
36
37
# File 'lib/rspec/risky.rb', line 35

def record_expectation(count = 1)
  Probe::ExpectationProbe.record_custom_expectation(count)
end

.risky_resultsObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/rspec/risky.rb', line 89

def risky_results
  return [] unless defined?(::RSpec::Core)

  ::RSpec.world.all_examples.filter_map do |example|
    result = example.[:rspec_risky]
    next unless result

    [example, result]
  end
end

.run_example(example_procsy) ⇒ Object

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rspec/risky.rb', line 58

def run_example(example_procsy)
  example = example_procsy.example
  expectation_state = Probe::ExpectationProbe.start(example)
  output_state = start_output_probe

  begin
    example_procsy.run
  ensure
    output_report = Probe::OutputProbe.finish(output_state)
    expectation_report = Probe::ExpectationProbe.finish(expectation_state)
    expectation_report.custom_expectation_count += configuration.unknown_test.adapter_count(example)
    verdicts = Verdict.evaluate(
      example: example,
      configuration: configuration,
      expectations: expectation_report,
      output: output_report
    )

    example.[:rspec_risky] = {
      custom_expectation_count: expectation_report.custom_expectation_count,
      expectation_count: expectation_report.expectation_count,
      mock_expectation_count: expectation_report.mock_expectation_count,
      output: output_report,
      verdicts: verdicts
    }
  end

  fail_verdicts = verdicts.select { |verdict| verdict.severity == :fail }
  raise RiskyExampleError.new(fail_verdicts) if fail_verdicts.any? && !example.exception
end