Class: Shoulda::Matchers::ViewComponent::UseCollectionParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/view_component/use_collection_parameter.rb

Instance Method Summary collapse

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

#descriptionObject



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_messageObject



65
66
67
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 65

def failure_message
  "expected #{@subject} to #{description}"
end

#failure_message_when_negatedObject



69
70
71
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 69

def failure_message_when_negated
  "expected #{@subject} not to #{description}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (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_counterObject



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_iterationObject



78
79
80
81
# File 'lib/shoulda/matchers/view_component/use_collection_parameter.rb', line 78

def with_iteration
  @with_iteration = true
  self
end