File: errors.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 (91 lines) | stat: -rw-r--r-- 2,215 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
88
89
90
91
# frozen_string_literal: true

module RSpec::Puppet
  module Errors
    class MatchError < StandardError
      attr_reader :param, :expected, :actual, :negative

      def initialize(param, expected, actual, negative)
        @param = param
        @expected = expected
        @actual = actual
        @negative = negative
      end

      def message
        if (@param.to_s == 'content') && expected.is_a?(String)
          if negative == true
            "#{param} not set to supplied string"
          else
            "#{param} set to supplied string"
          end
        elsif negative == true
          "#{param} not set to #{expected.inspect} but it is set to #{actual.inspect}"
        else
          "#{param} set to #{expected.inspect} but it is set to #{actual.inspect}"
        end
      end

      def to_s
        message
      end
    end

    class RegexpMatchError < MatchError
      def message
        if negative == true
          "#{param} not matching #{expected.inspect} but its value of #{actual.inspect} does"
        else
          "#{param} matching #{expected.inspect} but its value of #{actual.inspect} does not"
        end
      end
    end

    class ProcMatchError < MatchError
      def message
        if negative == true
          "#{param} passed to the block would not return `#{expected.inspect}` but it did"
        else
          "#{param} passed to the block would return `#{expected.inspect}` but it is `#{actual.inspect}`"
        end
      end
    end

    class RelationshipError < StandardError
      attr_reader :from, :to

      def initialize(from, to)
        @from = from
        @to = to
      end

      def to_s
        message
      end
    end

    class BeforeRelationshipError < RelationshipError
      def message
        "that comes before #{to}"
      end
    end

    class RequireRelationshipError < RelationshipError
      def message
        "that requires #{to}"
      end
    end

    class NotifyRelationshipError < RelationshipError
      def message
        "that notifies #{to}"
      end
    end

    class SubscribeRelationshipError < RelationshipError
      def message
        "that is subscribed to #{to}"
      end
    end
  end
end