Class: ValidateOptions::Spec::Matchers::ValidateOptionsMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/validate_options/spec.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(accepted_options) ⇒ ValidateOptionsMatcher

Returns a new instance of ValidateOptionsMatcher.



5
6
7
# File 'lib/validate_options/spec.rb', line 5

def initialize(accepted_options)
  @accepted_options = accepted_options
end

Instance Method Details

#failure_messageObject



29
30
31
# File 'lib/validate_options/spec.rb', line 29

def failure_message
  "expected block to validate options."
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/validate_options/spec.rb', line 9

def matches?(target)
  accepted = @accepted_options.all? do |opt|
    begin
      target.call(opt => nil)
      true
    rescue ArgumentError
      false
    end
  end
  
  rejected = begin
               target.call("___very_odd_probably_invalid_key" => nil)
               false
             rescue ArgumentError
               true
             end
  
  accepted && rejected
end