1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

allow_value: Inspect values more clearly

Modify descriptions and failure messages for all matchers by way of
allow_value and put small angle brackets around inspected values. This
is to visually distinguish an inspected value from the rest of the text,
and is especially noticeable for complex values such as an array that
contains an object, particularly if the inspected version of the value
wraps onto another line. It's a little easier to see:

    When attempting to set :attr on Example to ‹[#<Child id:
    nil>]›...

rather than:

    When attempting to set :attr on Example to [#<Child id:
    nil>]...
This commit is contained in:
Elliot Winkler 2015-12-22 02:00:51 -05:00
parent 417f289a86
commit 6b3253147a
17 changed files with 200 additions and 169 deletions

View file

@ -463,10 +463,13 @@ module Shoulda
end end
if expected_message.is_a?(Regexp) if expected_message.is_a?(Regexp)
message << ' matching' message << ' matching '
end message << Shoulda::Matchers::Util.inspect_value(
expected_message
)
else
message << " #{expected_message.inspect}" message << " #{expected_message.inspect}"
end
unless validator.captured_validation_exception? unless validator.captured_validation_exception?
message << " on :#{attribute_to_check_message_against}" message << " on :#{attribute_to_check_message_against}"
@ -577,14 +580,10 @@ module Shoulda
end end
def inspected_values_to_set def inspected_values_to_set
if values_to_set.size > 1 Shoulda::Matchers::Util.inspect_values(values_to_set).to_sentence(
values_to_set.map(&:inspect).to_sentence(
two_words_connector: " or ", two_words_connector: " or ",
last_word_connector: ", or" last_word_connector: ", or"
) )
else
values_to_set.first.inspect
end
end end
def default_expected_message def default_expected_message

View file

@ -25,11 +25,13 @@ module Shoulda
end end
def description def description
description = ":#{attribute_name} to #{value_written.inspect}" description = ":#{attribute_name} to "
description << Shoulda::Matchers::Util.inspect_value(value_written)
if attribute_changed_value? if attribute_changed_value?
description << " -- which was read back as " description << " -- which was read back as "
description << "#{value_read.inspect} --" description << Shoulda::Matchers::Util.inspect_value(value_read)
description << " --"
end end
description description

View file

@ -141,17 +141,15 @@ module Shoulda
def simple_description def simple_description
if @range if @range
"validate that :#{@attribute} lies outside the range #{@range.inspect}" "validate that :#{@attribute} lies outside the range " +
Shoulda::Matchers::Util.inspect_range(@range)
else else
description = "validate that :#{@attribute}" description = "validate that :#{@attribute}"
if @array.many? if @array.many?
description << " is neither " + @array.map(&:inspect).to_sentence( description << " is neither #{inspected_array}"
two_words_connector: " nor ",
last_word_connector: ", nor "
)
else else
description << " is not #{@array.first.inspect}" description << " is not #{inspected_array}"
end end
description description
@ -202,6 +200,13 @@ module Shoulda
@array.inspect @array.inspect
end end
end end
def inspected_array
Shoulda::Matchers::Util.inspect_values(@array).to_sentence(
two_words_connector: " nor ",
last_word_connector: ", nor "
)
end
end end
end end
end end

View file

@ -352,17 +352,15 @@ EOT
def simple_description def simple_description
if @range if @range
"validate that :#{@attribute} lies inside the range #{@range.inspect}" "validate that :#{@attribute} lies inside the range " +
Shoulda::Matchers::Util.inspect_range(@range)
else else
description = "validate that :#{@attribute}" description = "validate that :#{@attribute}"
if @array.many? if @array.many?
description << " is either " + @array.map(&:inspect).to_sentence( description << " is either #{inspected_array}"
two_words_connector: " or ",
last_word_connector: ", or "
)
else else
description << " is #{@array.first.inspect}" description << " is #{inspected_array}"
end end
description description
@ -552,6 +550,13 @@ EOT
else :unknown else :unknown
end end
end end
def inspected_array
Shoulda::Matchers::Util.inspect_values(@array).to_sentence(
two_words_connector: " or ",
last_word_connector: ", or "
)
end
end end
end end
end end

View file

@ -682,27 +682,35 @@ module Shoulda
if @existing_record_created if @existing_record_created
prefix << "After taking the given #{model.name}," prefix << "After taking the given #{model.name},"
prefix << " setting its :#{attribute} to" prefix << " setting its :#{attribute} to "
prefix << " #{existing_value.inspect}," prefix << Shoulda::Matchers::Util.inspect_value(existing_value)
prefix << " and saving it as the existing record," prefix << ", and saving it as the existing record,"
prefix << " then" prefix << " then"
elsif @original_existing_value != existing_value elsif @original_existing_value != existing_value
prefix << "Given an existing #{model.name}," prefix << "Given an existing #{model.name},"
prefix << " after setting its :#{attribute} to" prefix << " after setting its :#{attribute} to "
prefix << " #{existing_value.inspect}, then" prefix << Shoulda::Matchers::Util.inspect_value(existing_value)
prefix << ", then"
else else
prefix << "Given an existing #{model.name} whose :#{attribute}" prefix << "Given an existing #{model.name} whose :#{attribute}"
prefix << " is #{existing_value.inspect}, after" prefix << " is "
prefix << Shoulda::Matchers::Util.inspect_value(existing_value)
prefix << ", after"
end end
prefix << " making a new #{model.name} and setting its" prefix << " making a new #{model.name} and setting its"
prefix << " :#{attribute} to" prefix << " :#{attribute} to "
if last_value_set_on_new_record == existing_value if last_value_set_on_new_record == existing_value
prefix << " #{last_value_set_on_new_record.inspect} as well" prefix << Shoulda::Matchers::Util.inspect_value(
last_value_set_on_new_record
)
prefix << " as well"
else else
prefix << " a different value," prefix << " a different value, "
prefix << " #{last_value_set_on_new_record.inspect}" prefix << Shoulda::Matchers::Util.inspect_value(
last_value_set_on_new_record
)
end end
prefix << ", the matcher expected the new #{model.name} to be" prefix << ", the matcher expected the new #{model.name} to be"

View file

@ -38,6 +38,18 @@ module Shoulda
"a #{next_word}" "a #{next_word}"
end end
end end
def self.inspect_value(value)
"#{value.inspect}"
end
def self.inspect_values(values)
values.map { |value| inspect_value(value) }
end
def self.inspect_range(range)
"#{inspect_value(range.first)} to #{inspect_value(range.last)}"
end
end end
end end
end end

View file

@ -14,14 +14,14 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
matcher = allow_value('foo', 'bar').for(:baz) matcher = allow_value('foo', 'bar').for(:baz)
expect(matcher.description).to eq( expect(matcher.description).to eq(
'allow :baz to be "foo" or "bar"' 'allow :baz to be "foo" or "bar"'
) )
end end
it 'describes itself with a single value' do it 'describes itself with a single value' do
matcher = allow_value('foo').for(:baz) matcher = allow_value('foo').for(:baz)
expect(matcher.description).to eq 'allow :baz to be "foo"' expect(matcher.description).to eq 'allow :baz to be "foo"'
end end
if active_model_3_2? if active_model_3_2?
@ -29,7 +29,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
strict_matcher = allow_value('xyz').for(:attr).strict strict_matcher = allow_value('xyz').for(:attr).strict
expect(strict_matcher.description).to eq( expect(strict_matcher.description).to eq(
'allow :attr to be "xyz", raising a validation exception on failure' 'allow :attr to be "xyz", raising a validation exception on failure'
) )
end end
end end
@ -56,7 +56,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
it 'rejects a bad value with an appropriate failure message' do it 'rejects a bad value with an appropriate failure message' do
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
valid, but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["is invalid"] * attr: ["is invalid"]
@ -84,7 +84,7 @@ valid, but it was invalid instead, producing these validation errors:
it 'produces an appropriate failure message' do it 'produces an appropriate failure message' do
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "zyx", the matcher expected the Example to be After setting :attr to "zyx", the matcher expected the Example to be
valid, but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["is invalid"] * attr: ["is invalid"]
@ -110,7 +110,7 @@ valid, but it was invalid instead, producing these validation errors:
it 'rejects a bad value with an appropriate failure message' do it 'rejects a bad value with an appropriate failure message' do
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
valid, but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["bad value"] * attr: ["bad value"]
@ -127,10 +127,10 @@ valid, but it was invalid instead, producing these validation errors:
context 'when the custom messages do not match' do context 'when the custom messages do not match' do
it 'rejects with an appropriate failure message' do it 'rejects with an appropriate failure message' do
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
invalid and to produce a validation error matching /different/ on :attr. invalid and to produce a validation error matching /different/ on
The record was indeed invalid, but it produced these validation errors :attr. The record was indeed invalid, but it produced these validation
instead: errors instead:
* attr: ["bad value"] * attr: ["bad value"]
MESSAGE MESSAGE
@ -186,7 +186,7 @@ instead:
end end
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
invalid and to produce the validation error "must be greater than 2" on invalid and to produce the validation error "must be greater than 2" on
:attr. The record was indeed invalid, but it produced these validation :attr. The record was indeed invalid, but it produced these validation
errors instead: errors instead:
@ -249,7 +249,7 @@ errors instead:
end end
message = <<-MESSAGE message = <<-MESSAGE
After setting :#{builder.attribute_to_validate} to "#{invalid_value}", the After setting :#{builder.attribute_to_validate} to "#{invalid_value}", the
matcher expected the #{builder.model.name} to be invalid and to produce the validation matcher expected the #{builder.model.name} to be invalid and to produce the validation
error "some error" on :#{builder.attribute_that_receives_error}. The record was error "some error" on :#{builder.attribute_that_receives_error}. The record was
indeed invalid, but it produced these validation errors instead: indeed invalid, but it produced these validation errors instead:
@ -341,7 +341,7 @@ indeed invalid, but it produced these validation errors instead:
it "does not match given good values along with bad values" do it "does not match given good values along with bad values" do
message = <<-MESSAGE.strip_heredoc message = <<-MESSAGE.strip_heredoc
After setting :attr to "12345", the matcher expected the Example to be After setting :attr to "12345", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -375,7 +375,7 @@ invalid, but it was valid instead.
context 'when qualified with strict' do context 'when qualified with strict' do
it 'rejects a bad value, providing the correct failure message' do it 'rejects a bad value, providing the correct failure message' do
message = <<-MESSAGE.strip_heredoc message = <<-MESSAGE.strip_heredoc
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
valid, but it was invalid instead, raising a validation exception with valid, but it was invalid instead, raising a validation exception with
the message "Attr is invalid". the message "Attr is invalid".
MESSAGE MESSAGE
@ -391,10 +391,10 @@ the message "Attr is invalid".
context 'qualified with a custom message' do context 'qualified with a custom message' do
it 'rejects a bad value when the failure messages do not match' do it 'rejects a bad value when the failure messages do not match' do
message = <<-MESSAGE.strip_heredoc message = <<-MESSAGE.strip_heredoc
After setting :attr to "xyz", the matcher expected the Example to be After setting :attr to "xyz", the matcher expected the Example to be
invalid and to raise a validation exception with message matching /abc/. invalid and to raise a validation exception with message matching
The record was indeed invalid, but the exception message was "Attr is /abc/. The record was indeed invalid, but the exception message was
invalid" instead. "Attr is invalid" instead.
MESSAGE MESSAGE
assertion = lambda do assertion = lambda do

View file

@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::EvenNumberMatcher
end end
message = <<-MESSAGE.strip_heredoc message = <<-MESSAGE.strip_heredoc
After setting :attr to "1", the matcher expected the Example to be After setting :attr to "1", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE

View file

@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OddNumberMatcher
end end
message = <<-MESSAGE.strip_heredoc message = <<-MESSAGE.strip_heredoc
After setting :attr to "2", the matcher expected the Example to be After setting :attr to "2", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE

View file

@ -31,7 +31,7 @@ describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OnlyIntegerMatche
end end
message = <<-MESSAGE message = <<-MESSAGE
After setting :attr to "0.1", the matcher expected the Example to be After setting :attr to "0.1", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE

View file

@ -42,8 +42,8 @@ describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher, type: :model
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is empty/falsy. Example did not properly validate that :attr is empty/falsy.
After setting :attr to "an arbitrary value", the matcher expected the After setting :attr to "an arbitrary value", the matcher expected
Example to be invalid, but it was valid instead. the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
assertion = lambda do assertion = lambda do
@ -68,8 +68,8 @@ Example did not properly validate that :attr is empty/falsy.
it 'rejects with the correct failure message' do it 'rejects with the correct failure message' do
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is empty/falsy. Example did not properly validate that :attr is empty/falsy.
After setting :attr to "an arbitrary value", the matcher expected the After setting :attr to "an arbitrary value", the matcher expected
Example to be invalid, but it was valid instead. the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
assertion = lambda do assertion = lambda do
@ -106,7 +106,7 @@ Example did not properly validate that :attr is empty/falsy.
message = <<-MESSAGE message = <<-MESSAGE
Parent did not properly validate that :children is empty/falsy. Parent did not properly validate that :children is empty/falsy.
After setting :children to [#<Child id: nil>], the matcher expected After setting :children to [#<Child id: nil>], the matcher expected
the Parent to be invalid, but it was valid instead. the Parent to be invalid, but it was valid instead.
MESSAGE MESSAGE

View file

@ -82,8 +82,8 @@ on the Example, but that attribute does not exist.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that Example did not properly validate that
:attribute_to_confirm_confirmation matches :attribute_to_confirm. :attribute_to_confirm_confirmation matches :attribute_to_confirm.
After setting :attribute_to_confirm_confirmation to "some value", then After setting :attribute_to_confirm_confirmation to "some value",
setting :attribute_to_confirm to "different value", the matcher then setting :attribute_to_confirm to "different value", the matcher
expected the Example to be invalid, but it was valid instead. expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE

View file

@ -62,7 +62,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :mode
matcher = validate_exclusion_of(:attr).in_range(1..10) matcher = validate_exclusion_of(:attr).in_range(1..10)
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr lies outside the range 1..10' 'validate that :attr lies outside the range 1 to 10'
) )
end end
end end
@ -86,7 +86,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :mode
context 'when there is one value' do context 'when there is one value' do
it 'has correct description' do it 'has correct description' do
expect(validate_exclusion_of(:attr).in_array([true]).description). expect(validate_exclusion_of(:attr).in_array([true]).description).
to eq 'validate that :attr is not true' to eq 'validate that :attr is not true'
end end
end end
@ -95,7 +95,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :mode
matcher = validate_exclusion_of(:attr).in_array([true, 'dog']) matcher = validate_exclusion_of(:attr).in_array([true, 'dog'])
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr is neither true nor "dog"' 'validate that :attr is neither true nor "dog"'
) )
end end
end end
@ -105,7 +105,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :mode
matcher = validate_exclusion_of(:attr).in_array([true, 'dog', 'cat']) matcher = validate_exclusion_of(:attr).in_array([true, 'dog', 'cat'])
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr is neither true, "dog", nor "cat"' 'validate that :attr is neither true, "dog", nor "cat"'
) )
end end
end end

View file

@ -686,7 +686,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
matcher = validate_inclusion_of(:attr).in_array([true]) matcher = validate_inclusion_of(:attr).in_array([true])
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr is true' 'validate that :attr is true'
) )
end end
end end
@ -696,7 +696,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
matcher = validate_inclusion_of(:attr).in_array([true, 'dog']) matcher = validate_inclusion_of(:attr).in_array([true, 'dog'])
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr is either true or "dog"' 'validate that :attr is either true or "dog"'
) )
end end
end end
@ -706,7 +706,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
matcher = validate_inclusion_of(:attr).in_array([true, 'dog', 'cat']) matcher = validate_inclusion_of(:attr).in_array([true, 'dog', 'cat'])
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr is either true, "dog", or "cat"' 'validate that :attr is either true, "dog", or "cat"'
) )
end end
end end
@ -717,7 +717,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
matcher = validate_inclusion_of(:attr).in_range(1..10) matcher = validate_inclusion_of(:attr).in_range(1..10)
expect(matcher.description).to eq( expect(matcher.description).to eq(
'validate that :attr lies inside the range 1..10' 'validate that :attr lies inside the range 1 to 10'
) )
end end
end end

View file

@ -172,8 +172,8 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number. Example did not properly validate that :attr looks like a number.
After setting :attr to "abcd", the matcher expected the Example to be After setting :attr to "abcd", the matcher expected the Example to
invalid, but it was valid instead. be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -200,8 +200,8 @@ Example did not properly validate that :attr looks like a number.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number, but Example did not properly validate that :attr looks like a number, but
only if it is not nil. only if it is not nil.
In checking that Example allows :attr to be nil, after setting :attr In checking that Example allows :attr to be nil, after setting :attr
to nil, the matcher expected the Example to be valid, but it was to nil, the matcher expected the Example to be valid, but it was
invalid instead, producing these validation errors: invalid instead, producing these validation errors:
* attr: ["is not a number"] * attr: ["is not a number"]
@ -230,7 +230,7 @@ only if it is not nil.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like an integer. Example did not properly validate that :attr looks like an integer.
After setting :attr to "0.1", the matcher expected the Example to be After setting :attr to "0.1", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -290,7 +290,7 @@ Example did not properly validate that :attr looks like an integer.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like an odd number. Example did not properly validate that :attr looks like an odd number.
After setting :attr to "2", the matcher expected the Example to be After setting :attr to "2", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -350,7 +350,7 @@ Example did not properly validate that :attr looks like an odd number.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like an even number. Example did not properly validate that :attr looks like an even number.
After setting :attr to "1", the matcher expected the Example to be After setting :attr to "1", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -413,7 +413,7 @@ Example did not properly validate that :attr looks like an even number.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number less Example did not properly validate that :attr looks like a number less
than or equal to 18. than or equal to 18.
After setting :attr to "19", the matcher expected the Example to be After setting :attr to "19", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -476,7 +476,7 @@ than or equal to 18.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number less Example did not properly validate that :attr looks like a number less
than 18. than 18.
After setting :attr to "19", the matcher expected the Example to be After setting :attr to "19", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -537,7 +537,7 @@ than 18.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number equal Example did not properly validate that :attr looks like a number equal
to 18. to 18.
After setting :attr to "19", the matcher expected the Example to be After setting :attr to "19", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -609,7 +609,7 @@ to 18.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number greater Example did not properly validate that :attr looks like a number greater
than or equal to 18. than or equal to 18.
After setting :attr to "17", the matcher expected the Example to be After setting :attr to "17", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -678,7 +678,7 @@ than or equal to 18.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number greater Example did not properly validate that :attr looks like a number greater
than 18. than 18.
After setting :attr to "18", the matcher expected the Example to be After setting :attr to "18", the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -706,10 +706,10 @@ than 18.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number, Example did not properly validate that :attr looks like a number,
producing a custom validation error on failure. producing a custom validation error on failure.
After setting :attr to "abcd", the matcher expected the Example to be After setting :attr to "abcd", the matcher expected the Example to
invalid and to produce a validation error matching /wrong/ on :attr. be invalid and to produce a validation error matching /wrong/ on
The record was indeed invalid, but it produced these validation errors :attr. The record was indeed invalid, but it produced these validation
instead: errors instead:
* attr: ["custom"] * attr: ["custom"]
MESSAGE MESSAGE
@ -736,8 +736,8 @@ producing a custom validation error on failure.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number, Example did not properly validate that :attr looks like a number,
producing a custom validation error on failure. producing a custom validation error on failure.
After setting :attr to "abcd", the matcher expected the Example to be After setting :attr to "abcd", the matcher expected the Example to
invalid, but it was valid instead. be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -764,9 +764,9 @@ producing a custom validation error on failure.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number, Example did not properly validate that :attr looks like a number,
raising a validation exception on failure. raising a validation exception on failure.
After setting :attr to "abcd", the matcher expected the Example to be After setting :attr to "abcd", the matcher expected the Example to
invalid and to raise a validation exception, but the record produced be invalid and to raise a validation exception, but the record
validation errors instead. produced validation errors instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -798,8 +798,8 @@ raising a validation exception on failure.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr looks like a number. Example did not properly validate that :attr looks like a number.
After setting :attr to "abcd", the matcher expected the Example to be After setting :attr to "abcd", the matcher expected the Example to
invalid, but it was valid instead. be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -837,7 +837,7 @@ Example did not properly validate that :attr looks like a number.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18. greater than 18.
In checking that Example disallows :attr from being a decimal number, In checking that Example disallows :attr from being a decimal number,
after setting :attr to "0.1", the matcher expected the Example to be after setting :attr to "0.1", the matcher expected the Example to be
invalid and to produce the validation error "must be an integer" on invalid and to produce the validation error "must be an integer" on
:attr. The record was indeed invalid, but it produced these validation :attr. The record was indeed invalid, but it produced these validation
errors instead: errors instead:
@ -862,7 +862,7 @@ greater than 18.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18. greater than 18.
In checking that Example disallows :attr from being a decimal number, In checking that Example disallows :attr from being a decimal number,
after setting :attr to "0.1", the matcher expected the Example to be after setting :attr to "0.1", the matcher expected the Example to be
invalid and to produce the validation error "must be an integer" on invalid and to produce the validation error "must be an integer" on
:attr. The record was indeed invalid, but it produced these validation :attr. The record was indeed invalid, but it produced these validation
errors instead: errors instead:
@ -890,8 +890,8 @@ greater than 18.
Example did not properly validate that :attr looks like an even number Example did not properly validate that :attr looks like an even number
greater than 18. greater than 18.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid, but it was valid instead. expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -914,7 +914,7 @@ greater than 18.
Example did not properly validate that :attr looks like an even number Example did not properly validate that :attr looks like an even number
greater than 18. greater than 18.
In checking that Example disallows :attr from being an odd number, In checking that Example disallows :attr from being an odd number,
after setting :attr to "1", the matcher expected the Example to be after setting :attr to "1", the matcher expected the Example to be
invalid and to produce the validation error "must be even" on :attr. invalid and to produce the validation error "must be even" on :attr.
The record was indeed invalid, but it produced these validation errors The record was indeed invalid, but it produced these validation errors
instead: instead:
@ -942,7 +942,7 @@ greater than 18.
Example did not properly validate that :attr looks like an odd number Example did not properly validate that :attr looks like an odd number
less than or equal to 99. less than or equal to 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not less than or equal to 99, after setting :attr to "101", the not less than or equal to 99, after setting :attr to "101", the
matcher expected the Example to be invalid, but it was valid instead. matcher expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
@ -968,8 +968,8 @@ less than or equal to 99.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18 and less than 99. greater than 18 and less than 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid, but it was valid instead. expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -995,10 +995,10 @@ greater than 18 and less than 99.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18. greater than 18.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid and to produce the validation error "must be expected the Example to be invalid and to produce the validation error
greater than 18" on :attr. The record was indeed invalid, but it "must be greater than 18" on :attr. The record was indeed invalid, but
produced these validation errors instead: it produced these validation errors instead:
* attr: ["must be greater than 19"] * attr: ["must be greater than 19"]
MESSAGE MESSAGE
@ -1023,8 +1023,8 @@ greater than 18.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18. greater than 18.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid, but it was valid instead. expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -1048,10 +1048,10 @@ greater than 18.
Example did not properly validate that :attr looks like an even number Example did not properly validate that :attr looks like an even number
greater than 18. greater than 18.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid and to produce the validation error "must be expected the Example to be invalid and to produce the validation error
greater than 18" on :attr. The record was indeed invalid, but it "must be greater than 18" on :attr. The record was indeed invalid, but
produced these validation errors instead: it produced these validation errors instead:
* attr: ["must be greater than 20"] * attr: ["must be greater than 20"]
MESSAGE MESSAGE
@ -1076,8 +1076,8 @@ greater than 18.
Example did not properly validate that :attr looks like an even number Example did not properly validate that :attr looks like an even number
greater than 18. greater than 18.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid, but it was valid instead. expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -1100,7 +1100,7 @@ greater than 18.
Example did not properly validate that :attr looks like an odd number Example did not properly validate that :attr looks like an odd number
less than or equal to 99. less than or equal to 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not less than or equal to 99, after setting :attr to "101", the not less than or equal to 99, after setting :attr to "101", the
matcher expected the Example to be invalid, but it was valid instead. matcher expected the Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
@ -1124,7 +1124,7 @@ less than or equal to 99.
Example did not properly validate that :attr looks like an odd number Example did not properly validate that :attr looks like an odd number
less than or equal to 99. less than or equal to 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not less than or equal to 99, after setting :attr to "101", the not less than or equal to 99, after setting :attr to "101", the
matcher expected the Example to be invalid and to produce the matcher expected the Example to be invalid and to produce the
validation error "must be less than or equal to 99" on :attr. The validation error "must be less than or equal to 99" on :attr. The
record was indeed invalid, but it produced these validation errors record was indeed invalid, but it produced these validation errors
@ -1156,10 +1156,10 @@ less than or equal to 99.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18 and less than 99. greater than 18 and less than 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not greater than 18, after setting :attr to "18", the matcher expected not greater than 18, after setting :attr to "18", the matcher
the Example to be invalid and to produce the validation error "must be expected the Example to be invalid and to produce the validation error
greater than 18" on :attr. The record was indeed invalid, but it "must be greater than 18" on :attr. The record was indeed invalid, but
produced these validation errors instead: it produced these validation errors instead:
* attr: ["must be greater than 19"] * attr: ["must be greater than 19"]
MESSAGE MESSAGE
@ -1186,7 +1186,7 @@ greater than 18 and less than 99.
Example did not properly validate that :attr looks like an integer Example did not properly validate that :attr looks like an integer
greater than 18 and less than 99. greater than 18 and less than 99.
In checking that Example disallows :attr from being a number that is In checking that Example disallows :attr from being a number that is
not less than 99, after setting :attr to "100", the matcher expected not less than 99, after setting :attr to "100", the matcher expected
the Example to be invalid and to produce the validation error "must be the Example to be invalid and to produce the validation error "must be
less than 99" on :attr. The record was indeed invalid, but it produced less than 99" on :attr. The record was indeed invalid, but it produced
these validation errors instead: these validation errors instead:

View file

@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher, type: :model
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr cannot be empty/falsy. Example did not properly validate that :attr cannot be empty/falsy.
After setting :attr to nil, the matcher expected the Example to be After setting :attr to nil, the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -47,7 +47,7 @@ Example did not properly validate that :attr cannot be empty/falsy.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr cannot be empty/falsy. Example did not properly validate that :attr cannot be empty/falsy.
After setting :attr to nil, the matcher expected the Example to be After setting :attr to nil, the matcher expected the Example to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -105,7 +105,7 @@ Example did not properly validate that :attr cannot be empty/falsy.
message = <<-MESSAGE message = <<-MESSAGE
Parent did not properly validate that :children cannot be empty/falsy. Parent did not properly validate that :children cannot be empty/falsy.
After setting :children to [], the matcher expected the Parent to be After setting :children to [], the matcher expected the Parent to be
invalid, but it was valid instead. invalid, but it was valid instead.
MESSAGE MESSAGE
@ -143,7 +143,7 @@ Parent did not properly validate that :children cannot be empty/falsy.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr cannot be empty/falsy, Example did not properly validate that :attr cannot be empty/falsy,
raising a validation exception on failure. raising a validation exception on failure.
After setting :attr to nil, the matcher expected the Example to be After setting :attr to nil, the matcher expected the Example to be
invalid and to raise a validation exception, but the record produced invalid and to raise a validation exception, but the record produced
validation errors instead. validation errors instead.
MESSAGE MESSAGE

View file

@ -247,9 +247,9 @@ within the scope of :non_existent1 and :non_existent2.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique. Example did not properly validate that :attr is case-sensitively unique.
Given an existing Example whose :attr is "value", after making a new Given an existing Example whose :attr is "value", after making a new
Example and setting its :attr to "value" as well, the matcher expected Example and setting its :attr to "value" as well, the matcher
the new Example to be invalid, but it was valid instead. expected the new Example to be invalid, but it was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -347,9 +347,9 @@ within the scope of :other.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique. Example did not properly validate that :attr is case-sensitively unique.
After taking the given Example, setting its :attr to "an arbitrary After taking the given Example, setting its :attr to "an arbitrary
value", and saving it as the existing record, then making a new value", and saving it as the existing record, then making a new
Example and setting its :attr to "an arbitrary value" as well, the Example and setting its :attr to "an arbitrary value" as well, the
matcher expected the new Example to be invalid and to produce the matcher expected the new Example to be invalid and to produce the
validation error "has already been taken" on :attr. The record was validation error "has already been taken" on :attr. The record was
indeed invalid, but it produced these validation errors instead: indeed invalid, but it produced these validation errors instead:
@ -377,9 +377,9 @@ Example did not properly validate that :attr is case-sensitively unique.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
producing a custom validation error on failure. producing a custom validation error on failure.
After taking the given Example, setting its :attr to "an arbitrary After taking the given Example, setting its :attr to "an arbitrary
value", and saving it as the existing record, then making a new value", and saving it as the existing record, then making a new
Example and setting its :attr to "an arbitrary value" as well, the Example and setting its :attr to "an arbitrary value" as well, the
matcher expected the new Example to be invalid and to produce the matcher expected the new Example to be invalid and to produce the
validation error "some message" on :attr. The record was indeed validation error "some message" on :attr. The record was indeed
invalid, but it produced these validation errors instead: invalid, but it produced these validation errors instead:
@ -419,11 +419,11 @@ producing a custom validation error on failure.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
producing a custom validation error on failure. producing a custom validation error on failure.
After taking the given Example, setting its :attr to "an arbitrary After taking the given Example, setting its :attr to "an arbitrary
value", and saving it as the existing record, then making a new value", and saving it as the existing record, then making a new
Example and setting its :attr to "an arbitrary value" as well, the Example and setting its :attr to "an arbitrary value" as well, the
matcher expected the new Example to be invalid and to produce a matcher expected the new Example to be invalid and to produce a
validation error matching /some message/ on :attr. The record was validation error matching /some message/ on :attr. The record was
indeed invalid, but it produced these validation errors instead: indeed invalid, but it produced these validation errors instead:
* attr: ["something else entirely"] * attr: ["something else entirely"]
@ -672,11 +672,11 @@ within the scope of :scope1.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-insensitively Example did not properly validate that :attr is case-insensitively
unique. unique.
After taking the given Example, setting its :attr to "an arbitrary After taking the given Example, setting its :attr to "an arbitrary
value", and saving it as the existing record, then making a new value", and saving it as the existing record, then making a new
Example and setting its :attr to a different value, "AN ARBITRARY Example and setting its :attr to a different value, "AN ARBITRARY
VALUE", the matcher expected the new Example to be invalid, but it was VALUE", the matcher expected the new Example to be invalid, but it
valid instead. was valid instead.
MESSAGE MESSAGE
expect(&assertion).to fail_with_message(message) expect(&assertion).to fail_with_message(message)
@ -698,10 +698,10 @@ unique.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique. Example did not properly validate that :attr is case-sensitively unique.
After taking the given Example, setting its :attr to "an arbitrary After taking the given Example, setting its :attr to "an arbitrary
value", and saving it as the existing record, then making a new value", and saving it as the existing record, then making a new
Example and setting its :attr to a different value, "AN ARBITRARY Example and setting its :attr to a different value, "AN ARBITRARY
VALUE", the matcher expected the new Example to be valid, but it was VALUE", the matcher expected the new Example to be valid, but it was
invalid instead, producing these validation errors: invalid instead, producing these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
@ -775,9 +775,9 @@ Example did not properly validate that :attr is case-sensitively unique.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not nil. but only if it is not nil.
After taking the given Example, setting its :attr to nil, and saving After taking the given Example, setting its :attr to nil, and saving
it as the existing record, then making a new Example and setting its it as the existing record, then making a new Example and setting its
:attr to nil as well, the matcher expected the new Example to be :attr to nil as well, the matcher expected the new Example to be
valid, but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
@ -799,10 +799,10 @@ but only if it is not nil.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not nil. but only if it is not nil.
Given an existing Example whose :attr is nil, after making a new Given an existing Example whose :attr is nil, after making a new
Example and setting its :attr to nil as well, the matcher expected the Example and setting its :attr to nil as well, the matcher expected
new Example to be valid, but it was invalid instead, producing these the new Example to be valid, but it was invalid instead, producing
validation errors: these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
MESSAGE MESSAGE
@ -904,10 +904,10 @@ but only if it is not nil.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not blank. but only if it is not blank.
After taking the given Example, setting its :attr to "", and saving it After taking the given Example, setting its :attr to "", and saving
as the existing record, then making a new Example and setting its it as the existing record, then making a new Example and setting its
:attr to "" as well, the matcher expected the new Example to be valid, :attr to "" as well, the matcher expected the new Example to be
but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
MESSAGE MESSAGE
@ -928,10 +928,10 @@ but only if it is not blank.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not blank. but only if it is not blank.
Given an existing Example, after setting its :attr to "", then making Given an existing Example, after setting its :attr to "", then
a new Example and setting its :attr to "" as well, the matcher making a new Example and setting its :attr to "" as well, the
expected the new Example to be valid, but it was invalid instead, matcher expected the new Example to be valid, but it was invalid
producing these validation errors: instead, producing these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
MESSAGE MESSAGE
@ -954,10 +954,10 @@ but only if it is not blank.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not blank. but only if it is not blank.
After taking the given Example, setting its :attr to "", and saving it After taking the given Example, setting its :attr to "", and saving
as the existing record, then making a new Example and setting its it as the existing record, then making a new Example and setting its
:attr to "" as well, the matcher expected the new Example to be valid, :attr to "" as well, the matcher expected the new Example to be
but it was invalid instead, producing these validation errors: valid, but it was invalid instead, producing these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
MESSAGE MESSAGE
@ -980,10 +980,10 @@ but only if it is not blank.
message = <<-MESSAGE message = <<-MESSAGE
Example did not properly validate that :attr is case-sensitively unique, Example did not properly validate that :attr is case-sensitively unique,
but only if it is not blank. but only if it is not blank.
Given an existing Example whose :attr is "", after making a new Given an existing Example whose :attr is "", after making a new
Example and setting its :attr to "" as well, the matcher expected the Example and setting its :attr to "" as well, the matcher expected
new Example to be valid, but it was invalid instead, producing these the new Example to be valid, but it was invalid instead, producing
validation errors: these validation errors:
* attr: ["has already been taken"] * attr: ["has already been taken"]
MESSAGE MESSAGE