Class: Shoulda::Matchers::ViewComponent::UseCollectionParameter
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ViewComponent::UseCollectionParameter
- Defined in:
- lib/shoulda/matchers/view_component/use_collection_parameter.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attribute) ⇒ UseCollectionParameter
constructor
A new instance of UseCollectionParameter.
- #matches?(subject) ⇒ Boolean
- #with_counter ⇒ Object
- #with_iteration ⇒ Object
Constructor Details
#initialize(attribute) ⇒ UseCollectionParameter
Returns a new instance of UseCollectionParameter.
34 35 36 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 34 def initialize(attribute) @attribute = attribute.to_s end |
Instance Method Details
#description ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 46 def description description = "use collection parameter " \ ":#{@attribute} with matching #initialize(#{@attribute}:" if @with_counter description += ", #{@attribute}_counter:" end if @with_iteration description += ", #{@attribute}_iteration:" end description += '[, ...]) keyword argument' description += 's' if @with_counter || @with_iteration description end |
#failure_message ⇒ Object
65 66 67 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 65 def "expected #{@subject} to #{description}" end |
#failure_message_when_negated ⇒ Object
69 70 71 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 69 def "expected #{@subject} not to #{description}" end |
#matches?(subject) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 38 def matches?(subject) @subject = subject collection_parameter_matches? && has_matching_initialize_parameter? && requires_counter? && requires_iteration? end |
#with_counter ⇒ Object
73 74 75 76 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 73 def with_counter @with_counter = true self end |
#with_iteration ⇒ Object
78 79 80 81 |
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 78 def with_iteration @with_iteration = true self end |