Finds message information from exceptions thrown by valid?
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 6 def initialize(instance, attribute, context=nil) @instance = instance @attribute = attribute @context = context end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 12 def allow_description(allowed_values) "doesn't raise when #{@attribute} is set to #{allowed_values}" end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 36 def expected_message_from(attribute_message) "#{human_attribute_name} #{attribute_message}" end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 24 def has_messages? messages.any? end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 28 def messages @messages ||= validate_and_rescue end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 16 def messages_description if has_messages? messages.join else 'no exception' end end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 32 def source_description 'exception' end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 49 def human_attribute_name @instance.class.human_attribute_name(@attribute) end
# File lib/shoulda/matchers/active_model/exception_message_finder.rb, line 42 def validate_and_rescue @instance.valid?(@context) [] rescue ::ActiveModel::StrictValidationFailed => exception [exception.message] end