Class: RSpecial::Have
- Inherits:
-
Object
- Object
- RSpecial::Have
- Defined in:
- lib/rspecial/have.rb
Overview
Delegate to Have Assays.
Defined Under Namespace
Modules: Helpers
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
readonly
Returns the value of attribute collection_name.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Instance Method Summary collapse
- #collection(collection_or_owner) ⇒ Object
-
#initialize(expected, relation = :exactly) ⇒ Have
constructor
Initialize new Have delegator.
- #method_missing(method, *args, &block) ⇒ Object
- #query_method(collection) ⇒ Object
Constructor Details
#initialize(expected, relation = :exactly) ⇒ Have
Initialize new Have delegator.
16 17 18 19 20 21 22 23 24 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 |
Instance Attribute Details
#collection_name ⇒ Object (readonly)
Returns the value of attribute collection_name.
9 10 11 |
# File 'lib/rspecial/have.rb', line 9 def collection_name @collection_name end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
7 8 9 |
# File 'lib/rspecial/have.rb', line 7 def expected @expected end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
11 12 13 |
# File 'lib/rspecial/have.rb', line 11 def relation @relation end |
Instance Method Details
#collection(collection_or_owner) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# 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 |
#query_method(collection) ⇒ Object
42 43 44 |
# File 'lib/rspecial/have.rb', line 42 def query_method(collection) [:size, :length, :count].detect {|m| collection.respond_to?(m)} end |