module RSpecial::Have::Helpers

Public Class Methods

assert_description(collection_or_owner, have) click to toggle source

TODO: use when verbose error message mode

# File lib/rspecial/have.rb, line 106
def self.assert_description(collection_or_owner, have)
  collection, method, actual = collection_set(collection_or_owner, have)
  "expected #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}"
end
refute_descrptipon(collection_or_owner, have) click to toggle source
# File lib/rspecial/have.rb, line 114
def self.refute_descrptipon(collection_or_owner, have)
  collection, method, actual = collection_set(collection_or_owner, have)
  "expected not to have #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}"
end

Public Instance Methods

collection_actual(collection_or_owner, have) click to toggle source

Return the actual size of the collection.

# File lib/rspecial/have.rb, line 85
def collection_actual(collection_or_owner, have)
  collection_set(collection_or_owner, have).last
end
collection_set(collection_or_owner, have) click to toggle source
# File lib/rspecial/have.rb, line 71
def collection_set(collection_or_owner, have)
  collection   = have.collection(collection_or_owner)
  query_method = query_method(collection)

  raise not_a_collection(have) unless query_method

  actual = collection.__send__(query_method)

  return collection, query_method, actual
end
not_a_collection(have) click to toggle source

Message to use when collection doesn’t respond to ‘size`, `length` or `count`.

# File lib/rspecial/have.rb, line 99
def not_a_collection(have)
  "expected #{have.collection_name} to be a collection but it does not respond to #length, #size or #count"
end
query_method(collection) click to toggle source

Which size method to use: ‘size`, `length` or `count`.

# File lib/rspecial/have.rb, line 92
def query_method(collection)
  [:size, :length, :count].detect {|m| collection.respond_to?(m)}
end