Class: Matchers::AutoRequireMatcher

Inherits:
Object
  • Object
show all
Defined in:
modules/lvm/spec/lib/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(*expected) ⇒ AutoRequireMatcher

Returns a new instance of AutoRequireMatcher.



4
5
6
# File 'modules/lvm/spec/lib/matchers.rb', line 4

def initialize(*expected)
    @expected = expected
end

Instance Method Details

#failure_message_for_shouldObject



16
17
18
# File 'modules/lvm/spec/lib/matchers.rb', line 16

def failure_message_for_should
    "expected resource autorequires (#{@autorequires.inspect}) to include #{@expected.inspect}"
end

#failure_message_for_should_notObject



19
20
21
# File 'modules/lvm/spec/lib/matchers.rb', line 19

def failure_message_for_should_not
    "expected resource autorequires (#{@autorequires.inspect}) to not include #{@expected.inspect}"
end

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'modules/lvm/spec/lib/matchers.rb', line 8

def matches?(resource)
    resource_type = resource.class
    configuration = resource_type.instance_variable_get(:@autorequires) || {}
    @autorequires = configuration.inject([]) do |memo, (param, block)|
        memo + resource.instance_eval(&block)
    end
    @autorequires.include?(@expected)
end