File: raise_error.rb

package info (click to toggle)
ruby-rspec-puppet 4.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: ruby: 6,377; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module RSpec::Puppet
  module GenericMatchers
    # Due to significant code base depending on the
    #
    #     is_expected.to raise_error Puppet::Error
    #
    # syntax, and removal of this syntax from RSpec, extend RSpec's built-in
    # `raise_error` matcher to accept a value target, e.g. a subject defined
    # as a lambda, e.g.:
    #
    #     subject(:catalogue) { lambda { load_catalogue } }
    #
    class RaiseError < RSpec::Matchers::BuiltIn::RaiseError
      def supports_value_expectations?
        true
      end
    end

    def raise_error(
      error = defined?(RSpec::Matchers::BuiltIn::RaiseError::UndefinedValue) ? RSpec::Matchers::BuiltIn::RaiseError::UndefinedValue : nil, message = nil, &block
    )
      RaiseError.new(error, message, &block)
    end
  end
end