Class: Shoulda::Matchers::ActiveModel::ValidationMessageFinder
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::ValidationMessageFinder
show all
- Includes:
- Helpers
- Defined in:
- lib/shoulda/matchers/active_model/validation_message_finder.rb
Instance Method Summary
collapse
Methods included from Helpers
#default_error_message, #format_validation_errors, #pretty_error_messages
Constructor Details
#initialize(instance, attribute, context = nil) ⇒ ValidationMessageFinder
Returns a new instance of ValidationMessageFinder.
8
9
10
11
12
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 8
def initialize(instance, attribute, context = nil)
@instance = instance
@attribute = attribute
@context = context
end
|
Instance Method Details
#allow_description(allowed_values) ⇒ Object
14
15
16
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 14
def allow_description(allowed_values)
"allow #{@attribute} to be set to #{allowed_values}"
end
|
#expected_message_from(attribute_message) ⇒ Object
18
19
20
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 18
def expected_message_from(attribute_message)
attribute_message
end
|
#has_messages? ⇒ Boolean
22
23
24
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 22
def has_messages?
errors.present?
end
|
#messages ⇒ Object
38
39
40
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 38
def messages
Array(messages_for_attribute)
end
|
#messages_description ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 30
def messages_description
if errors.empty?
' no errors'
else
" errors:\n#{pretty_error_messages(validated_instance)}"
end
end
|
#source_description ⇒ Object
26
27
28
|
# File 'lib/shoulda/matchers/active_model/validation_message_finder.rb', line 26
def source_description
'errors'
end
|