Commit Graph

9 Commits

Author SHA1 Message Date
Elliot Winkler bffc9c9b73 Refactor numericality matcher
This is part of a collection of commits that aim to improve failure
messages across the board. The goal here is to make the matcher easier
to debug when something goes wrong.

* Have the failure message describe what the matcher was trying to do
  when it failed.
* Make the description of the matcher more readable.
* Change how the matcher works by stopping at the first failing
  submatcher instead of running all submatchers. Coincidentally, pending
  tests involving a strict validation but a non-strict expectation now
  pass.
* Fix or fill in tests involving failure messages and descriptions to
  match these changes and recent changes to ValidationMatcher and
  allow_value.
2015-12-13 20:22:22 -07:00
Elliot Winkler 18b2859d25 Fix numericality matcher w/ numeric columns
Fix the matcher so it still raises a CouldNotSetAttributeError against a
numeric column, but only if the matcher has not been qualified at all.
When the matcher is qualified with anything else, then it's okay to use
a numeric column, as long as the matcher no longer asserts that the
record disallows a non-numeric value.
2015-10-08 23:37:08 -06:00
Elliot Winkler 9d9dc4e6b9 Tighten CouldNotSetAttributeError restriction
Why:

* Previously, `allow_value` would raise a CouldNotSetAttributeError
  if the value being set didn't match the value the attribute had after
  being set, but only if the attribute was being changed from nil to
  non-nil or non-nil to nil.
* It turns out it doesn't matter which value you're trying to set the
  attribute to -- if the attribute rejects that change it's confusing
  either way. (In fact, I was recently bit by a case in which I was
  trying to validate numericality of an attribute, where the writer
  method for that attribute was overridden to ensure that the attribute
  always stored a number and never contained non-number characters.
  This ended up making the numericality validation useless, of
  course -- but it caused confusion because the test acted in a way
  I didn't expect.)

To satisfy the above:

* `allow_value` now raises a CouldNotSetAttributeError if the attribute
  rejects the value being set in *any* way.
* However, add a `ignoring_interference_by_writer` qualifier so that
  it is possible to manually override this behavior.
* Fix tests that are failing now because of this new change:
  * Fix tests for allow_value matcher
  * Fix tests for numericality matcher
  * Remove tests for numericality matcher + integer column
    * An integer column will typecast any non-integer value to an
      integer.
    * Because of the typecasting, our tests for the numericality matcher
      against an integer column don't quite work, because we can't
      really test what happens when the attribute is set to a
      non-integer value. Now that `allow_value` is more strict, we're
      getting a CouldNotSetAttributeError when attempting to do so.
    * The tests mentioned were originally added to ensure that we are
      handling RangeErrors that ActiveRecord used to emit. This doesn't
      happen anymore, so the tests aren't necessary anymore either.
  * Fix tests for acceptance matcher
  * Fix tests for absence matcher
2015-09-27 14:56:59 -06:00
Elliot Winkler 4d8faed1c4 Generate docs using YARD 2014-06-20 16:41:32 -06:00
Elliot Winkler c22d7c89e0 Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
Yukio Mizuta bc110f73b9 Update numericality comarison matcher more accurate 2014-02-26 19:48:29 -08:00
Yukio Mizuta 806716c79c Improve ValidateNumericalityOfMatcher document expression 2014-01-31 09:47:50 -07:00
Christopher Chow 1878e89a13 Update deprecated matcher protocol for RSpec 3.
The methods failure_message_for_should and failure_message_for_should_not
have been updated to failure_message and failure_message_negated respectively.
Alias to the old methods to remain backwards compatibility with RSpec 2.
2013-12-24 22:34:26 +11:00
Elliot Winkler 27c065ba55 Move ValidateNumericalityOf submatchers to a subfolder 2013-12-14 12:04:36 -07:00