class Mongoid::Matchers::HaveDelegateMatcher
Create an matcher for delegate method
Usage:
it { is_expected.to delegate(:name).to(:author) } it { is_expected.to delegate(:day).to(:created_at).with_prefix(:date) }
Public Class Methods
new(*args)
click to toggle source
Set methods to look for
# File lib/matchers/delegates.rb, line 13 def initialize(*args) @delegated = args[0] @method = @delegated end
Public Instance Methods
description()
click to toggle source
# File lib/matchers/delegates.rb, line 34 def description "delegate : #{@method}" end
failure_message()
click to toggle source
# File lib/matchers/delegates.rb, line 38 def failure_message "expected #{@delegator} have delegator #{_method}" end
failure_message_when_negated()
click to toggle source
# File lib/matchers/delegates.rb, line 42 def failure_message_when_negated "expected #{@delegator} have not to delegator :#{@method} #{prefix?}" end
matches?(klass)
click to toggle source
# File lib/matchers/delegates.rb, line 29 def matches?(klass) @delegator = klass @delegator.methods.include?(@method) end
to(to)
click to toggle source
# File lib/matchers/delegates.rb, line 18 def to(to) @to = to self end
with_prefix(prefix)
click to toggle source
# File lib/matchers/delegates.rb, line 23 def with_prefix(prefix) @prefix = prefix @method = :"#{@prefix}_#{@method}" self end
Private Instance Methods
_method()
click to toggle source
# File lib/matchers/delegates.rb, line 48 def _method if @prefix ":#{@delegated} with prefix :#{@prefix}" else ":#{@delegated}" end end
prefix?()
click to toggle source
# File lib/matchers/delegates.rb, line 56 def prefix? @prefix ? ' with prefix' : '' end