Module: Scryer::MinitestAssertions

Defined in:
lib/scryer/minitest.rb

Instance Method Summary collapse

Instance Method Details

#assert_no_critical_scryer_findings(result, msg = nil) ⇒ Object

Only security findings — style/performance findings aren't a security regression, same scoping as the RSpec have_no_critical_findings matcher.



26
27
28
29
30
31
32
33
# File 'lib/scryer/minitest.rb', line 26

def assert_no_critical_scryer_findings(result, msg = nil)
  criticals = result.security_findings.select { |f| f.severity == "critical" }
  default_msg = -> {
    lines = criticals.map { |f| "  - #{f.rule_id} at #{f.file}:#{f.line}#{f.message}" }
    "expected no critical security findings, but got #{criticals.size}:\n#{lines.join("\n")}"
  }
  assert criticals.empty?, msg || default_msg.call
end

#assert_no_scryer_findings_for(result, rule_id, msg = nil) ⇒ Object

Checks all three categories (security/performance/style) — a rule regressing is worth catching regardless of which category it's filed under, unlike assert_no_critical_scryer_findings above.



38
39
40
41
42
43
44
45
46
# File 'lib/scryer/minitest.rb', line 38

def assert_no_scryer_findings_for(result, rule_id, msg = nil)
  matches = (result.security_findings + result.performance_findings + result.style_findings)
            .select { |f| f.rule_id == rule_id.to_s }
  default_msg = -> {
    lines = matches.map { |f| "  - #{f.file}:#{f.line}#{f.message}" }
    "expected no findings for rule #{rule_id.inspect}, but got #{matches.size}:\n#{lines.join("\n")}"
  }
  assert matches.empty?, msg || default_msg.call
end