module ValidationMatcher

Constants

VERSION

Public Instance Methods

callback() click to toggle source
# File lib/validation_matcher.rb, line 33
def callback
  actual.class._validate_callbacks.detect { |c| c.filter == expected }
end
check_callback_options() click to toggle source
# File lib/validation_matcher.rb, line 37
def check_callback_options
  opts = parse_callback_options

  if @options.is_a? Hash
    raise 'Cannot expect custom procs' if @options.values.any? { |v| v.is_a? Proc }
    @options.each { |k, _| opts[k].should =~ Array(@options[k]) }
  else
    opts.keys.should =~ @options
  end
end
parse_callback_options() click to toggle source
# File lib/validation_matcher.rb, line 48
def parse_callback_options
  ifs = callback.instance_variable_get '@if'

  if ifs.first.is_a? Proc
    proc_binding = ifs.first.binding
    if proc_binding.local_variables.include? :options
      ons = proc_binding.local_variable_get(:options)[:on]
      ifs = ifs[1..-1]
    end
  end

  {
    if:     Array(ifs),
    on:     Array(ons),
    unless: Array(callback.instance_variable_get('@unless'))
  }.reject { |_, v| v.empty? }
end
validator() click to toggle source
# File lib/validation_matcher.rb, line 66
def validator
  actual.class.validators_on(@attribute).detect { |v| v.kind == expected }
end