Truncate long values in descriptions. Fixes #1041
This commit is contained in:
parent
390c2ca161
commit
8bf411fd44
|
@ -4,6 +4,8 @@ module Shoulda
|
|||
module Matchers
|
||||
# @private
|
||||
module Util
|
||||
MAXIMUM_LENGTH_OF_VALUE_TO_DISPLAY = 500
|
||||
|
||||
def self.deconstantize(path)
|
||||
if defined?(ActiveSupport::Inflector) &&
|
||||
ActiveSupport::Inflector.respond_to?(:deconstantize)
|
||||
|
@ -47,7 +49,12 @@ module Shoulda
|
|||
when Range
|
||||
inspect_range(value)
|
||||
else
|
||||
"‹#{value.inspect}›"
|
||||
inspected_value = value.inspect
|
||||
if inspected_value.length > MAXIMUM_LENGTH_OF_VALUE_TO_DISPLAY
|
||||
"‹#{inspected_value[0, MAXIMUM_LENGTH_OF_VALUE_TO_DISPLAY]}...›"
|
||||
else
|
||||
"‹#{inspected_value}›"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -41,6 +41,12 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
it 'truncates the description when long' do
|
||||
matcher = allow_value("A" * 10000).for(:baz)
|
||||
|
||||
expect(matcher.description).to eq "allow :baz to be ‹\"#{"A" * 499}...›"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#_after_setting_value' do
|
||||
|
|
Loading…
Reference in New Issue