class RSpecial::Have
Delegate to Have
Assays.
Attributes
collection_name[R]
expected[R]
relation[R]
Public Class Methods
new(expected, relation=:exactly)
click to toggle source
Initialize new Have
delegator.
# File lib/rspecial/have.rb, line 16 def initialize(expected, relation=:exactly) @expected = case expected when :no then 0 when String then expected.to_i else expected end @relation = relation @collection_name = nil end
Public Instance Methods
collection(collection_or_owner)
click to toggle source
@param [#size,#length,#count] collection_or_owner
# File lib/rspecial/have.rb, line 29 def collection(collection_or_owner) if collection_or_owner.respond_to?(@collection_name) collection_or_owner.__send__(@collection_name, *@args, &@block) elsif query_method(collection_or_owner) collection_or_owner else collection_or_owner.__send__(@collection_name, *@args, &@block) end end
method_missing(method, *args, &block)
click to toggle source
# File lib/rspecial/have.rb, line 49 def method_missing(method, *args, &block) @collection_name = method @args = args @block = block case @relation when :at_least RSpecial::HaveAtLeastAssay.assertor(self) when :at_most RSpecial::HaveAtMostAssay.assertor(self) else RSpecial::HaveExactlyAssay.assertor(self) end end
query_method(collection)
click to toggle source
# File lib/rspecial/have.rb, line 42 def query_method(collection) [:size, :length, :count].detect {|m| collection.respond_to?(m)} end