Module: RSpecial::Have::Helpers

Included in:
RSpecial::HaveAtLeastAssay, RSpecial::HaveAtMostAssay, RSpecial::HaveExactlyAssay
Defined in:
lib/rspecial/have.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assert_description(collection_or_owner, have) ⇒ Object

TODO: use when verbose error message mode



106
107
108
109
# 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) ⇒ Object



114
115
116
117
# 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

Instance Method Details

#collection_actual(collection_or_owner, have) ⇒ Object

Return the actual size of the collection.



85
86
87
# 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) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# 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) ⇒ Object

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



99
100
101
# 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) ⇒ Object

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



92
93
94
# File 'lib/rspecial/have.rb', line 92

def query_method(collection)
  [:size, :length, :count].detect {|m| collection.respond_to?(m)}
end