* Bring the file up to date style-wise with other matcher files
* Bring the tests up to date with other tests
* Improve error messaging
* Simplify documentation
Rails 5 made two changes to `belongs_to` associations:
* `required` and `optional` were added as options (which add and remove
a presence validation on the association, respectively)
* `required` was made the default
In addition, a `required` option was also added to `has_one`.
These new qualifiers allow us to test these options appropriately.
Credit: Shia <rise.shia@gmail.com>
Secondary author: Mauro George <maurogot@gmail.com>
Sometimes the failure message did not always provide the reason for
failure. For instance, given this validation:
validates :ano, numericality: { only_integer: true, greater_than_or_equal_to: 1900 }
this test:
it { should validate_numericality_of(:ano).is_greater_than_or_equal_to(1900) }
would fail with the following:
Did not expect errors when ano is set to 1900.000000000001, got error:
as you can see, the failure message doesn't contain the validation
error.
In the process of making this fix, we changed how the matcher fails so
that it will so when the first submatcher fails, not the last. This
changes what the failure message looks like, but not the basic
functionality of the matcher itself.
* Change 'spec' Rake task to 'spec:unit'
* Require unit_spec_helper.rb in unit tests, not spec_helper.rb
* Re-namespace files in spec/support/unit under UnitTests
* Files in spec/support/unit/helpers no longer automatically add
themselves to RSpec - this happens in unit_spec_helper.rb
* Extract RecordWithDifferentErrorAttributeBuilder and
RecordValidatingConfirmationBuilder to separate files
* Move spec/shoulda to spec/unit_tests/shoulda
* Move spec/support/*.rb to spec/support/unit_tests/{helpers,matchers}
* Move spec_helper.rb to unit_spec_helper.rb