File: raise_did_you_mean_error.rb

package info (click to toggle)
ruby-factory-bot 6.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,492 kB
  • sloc: ruby: 9,242; makefile: 6; sh: 4
file content (18 lines) | stat: -rw-r--r-- 536 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
RSpec::Matchers.define :raise_did_you_mean_error do
  supports_block_expectations

  match do |actual|
    # detailed_message introduced in Ruby 3.2 for cleaner integration with
    # did_you_mean. See https://bugs.ruby-lang.org/issues/18564
    matcher = if KeyError.method_defined?(:detailed_message)
      raise_error(
        an_instance_of(KeyError)
        .and(having_attributes(detailed_message: /Did you mean\?/))
      )
    else
      raise_error(KeyError, /Did you mean\?/)
    end

    expect(&actual).to matcher
  end
end