aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/assertions.rb
Commit message (Collapse)AuthorAgeFilesLines
* added tests for assert_no_difference with multiple expressionslxxxvi2018-07-081-0/+12
|
* Clearer error message in assert_changeslxxxvi2018-05-051-1/+3
| | | | When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message. Before, the message only contained the actual value.
* Support hash as first argument in `assert_difference`. (#31600)Julien Meichelbeck2018-01-181-7/+21
| | | | | | | | | | | | | | | | | * Support hash as first argument for `assert_difference`. This allows to specify multiple numeric differences in the same assertion. Example: assert_difference 'Article.count' => 1, 'Notification.count' => 2 do # post :create, params: { article: {...} } end * Support error message when passing a hash as a first parameter * Format CHANGELOG properly [Julien Meichelbeck + Rafael Mendonça França]
* `assert_changes` should always assert some changeDaniel Ma2017-11-131-5/+6
| | | | | | | | | | | | | | | | | | While using `assert_changes`, I came across some unexpected behavior: if you provide a `to:` argument, and the expression matches but didn't actually change, the assertion will pass. The way `assert_changes` reads, I assumed that it would both assert that there was any change at all, _and_ that the expression changed to match my `to:` argument. In the case of just a `from:` argument, `assert_changes` does what I expect as well. It asserts that the before value `=== from` and that the after value changed. My key change is that `assert_changes` will now _always_ assert that expression changes, no matter what combination of `from:` and `to:` arguments
* Use plain assert in assert_changes to avoid MT6 refutesGenadi Samokovarov2017-11-071-7/+2
| | | | | | | | | | | | | | | Seeing the previously issued PRs about it, we can avoid the `nil` comparisons that can happen in `assert_changes` by using plain `assert` calls. This is to avoid a deprecation warning about comparing `nil` values in `assert_equal` for Minitest 5 and a crash in Minitest 6. You can see the preparations done in [`assert_equal`][ae]. You can also see that [`assert`][a] does not care about `nil`s. [ae]: https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/lib/minitest/assertions.rb#L159-L188 [a]: https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/lib/minitest/assertions.rb#L131-L142
* Resolve Minitest 6 deprecation in assert_no_changesDan Ott2017-11-061-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | These changes resolve a deprecation warning in `assert_no_changes` when asserting that an expression evaluates to `nil` before and after the passed block is evaluated. The smallest demonstration of this edge case: ```ruby assert_no_changes "nil" do true # noop end ``` Under the covers, this is evaluating ```ruby assert_equal nil, nil ``` Minitest 5 issues a deprecation warning, and Minitest will fail completely. For additional context, the motivations and implications of this change to Minitest have been discussed at length in [seattlerb/minitest#666][]. [seattlerb/minitest#666]: https://github.com/seattlerb/minitest/issues/666
* fix typo in assert_changes error messageBoris Slobodin2017-07-311-1/+1
|
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add missing "not" in the doc for `assert_no_changes` [ci skip]Ryuta Kamizono2017-05-301-1/+1
|
* use `message` that specified in argument to error messageyuuji.yaginuma2016-08-311-1/+1
|
* use `inspect` for show `from` valueyuuji.yaginuma2016-08-291-1/+1
| | | | If `from` is nil, in order to avoid the blank is showed.
* Move custom assertion to its proper placeSantosh Wadghule2016-08-271-0/+11
| | | | | | | | ActiveSupport::Testing::Assertions. We have a separate module in which have defined Rails' own custom assertions. So it would be good to keep all custom Rails' assertions in one place i.e. in this module.
* Introduce `assert_changes` and `assert_no_changes`Genadi Samokovarov2016-07-171-0/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Those are assertions that I really do miss from the standard `ActiveSupport::TestCase`. Think of those as a more general version of `assert_difference` and `assert_no_difference` (those can be implemented by assert_changes, should this change be accepted). Why do we need those? They are useful when you want to check a side-effect of an operation. `assert_difference` do cover a really common case, but we `assert_changes` gives us more control. Having a global error flag? You can test it easily with `assert_changes`. In fact, you can be really specific about the initial state and the terminal one. ```ruby error = Error.new(:bad) assert_changes -> { Error.current }, from: nil, to: error do expected_bad_operation end ``` `assert_changes` follows `assert_difference` and a string can be given for evaluation as well. ```ruby error = Error.new(:bad) assert_changes 'Error.current', from: nil, to: error do expected_bad_operation end ``` Check out the test cases if you wanna see more examples. :beers:
* Remove an unused require in ActiveSupport::TestCaseGenadi Samokovarov2016-06-131-2/+0
| | | | We used to have `assert_blank` and `assert_presence`. [ci skip]
* Fixed wording in Assertion docs, changed ‘Assert’ -> ‘Asserts’Ronak Jangir2015-10-071-1/+1
|
* Make `assert_difference` return the result of the yielded block.Lucas Mazza2015-09-241-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | With this we can perform new assertions on the returned value without having to cache it with an outer variable or wrapping all subsequent assertions inside the `assert_difference` block. Before: ``` post = nil assert_difference -> { Post.count }, 1 do Post.create end assert_predicate post, :persisted? ``` Now: ``` post = assert_difference -> { Post.count } do Post.create end assert_predicate post, :persisted? ```
* Remove `assigns` and `assert_template`.Guo Xiang Tan2015-05-301-1/+1
|
* use keyword arguments in HTTP request methods of assert_difference example ↵yuuji.yaginuma2015-05-241-9/+9
| | | | [ci skip]
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* [ci skip] Correct output of #assert_notAkshay Vishnoi2014-06-121-1/+1
|
* remove deprecated `assert_present` and `assert_blank`.Yves Senn2013-07-011-30/+0
|
* deprecate `assert_blank` and `assert_present`.Yves Senn2013-01-051-0/+2
| | | | | They don't add any benefits over `assert object.blank?` and `assert object.present?`
* Introduce assert_not to replace 'assert !foo'Jeremy Kemper2012-12-281-0/+16
|
* update AS/notifications and AS/testing docs [ci skip]Francesco Rodriguez2012-09-141-3/+5
|
* fixes a few mistakes in api docs [ci skip]Vijay Dev2012-06-221-1/+1
|
* update AS::Testing::Assertions docsFrancesco Rodriguez2012-06-191-21/+32
|
* fix typo [ci skip]Francesco Rodriguez2012-06-191-2/+2
|
* Remove Array.wrap calls in ActiveSupportRafael Mendonça França2012-01-061-2/+1
|
* Fix syntax error in rdocs. Semyon Perepelitsa2011-12-201-1/+1
| | | Ruby assumes curly braces in foo {} as a block, for hash we need to put parentheses or omit braces
* fixing assert_difference issues on ruby 1.8Aaron Patterson2011-08-041-6/+7
|
* make assert_difference error message not suckAaron Patterson2011-08-031-5/+6
|
* correct error message for failed creationRay Baxter2011-06-261-1/+1
|
* convert strings to lambdas so we can use a consistent interface to the ↵Aaron Patterson2011-05-011-5/+5
| | | | objects in the collection
* assert_difference can take a callable piece of code rather than just evaling ↵Aaron Patterson2011-05-011-4/+15
| | | | a string
* code gardening: we have assert_(nil|blank|present), more concise, with ↵Xavier Noria2010-08-171-4/+6
| | | | better default failure messages - let's use them
* Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵Santiago Pastorino2010-08-141-2/+2
| | | | 's/[ \t]*$//' -i {} \;)
* adds missing require for blank? and present?Xavier Noria2010-03-311-0/+1
|
* New assertion: assert_present [#4299 state:committed]Juanjo Bazan2010-03-301-0/+7
| | | | Signed-off-by: Xavier Noria <fxn@hashref.com>
* new assertion: assert_blankJuanjo Bazan2010-03-301-0/+7
| | | | Signed-off-by: Xavier Noria <fxn@hashref.com>
* Fix dependencies revealed by testing in isolationJeremy Kemper2009-04-221-0/+2
|
* Oops, don't yield per expressionJeremy Kemper2009-02-061-10/+9
|
* Include failed difference expression in assert messageJeremy Kemper2009-02-061-8/+10
|
* Work around enumerable string deprecation warningsJeremy Kemper2009-02-061-6/+9
|
* Rework testing extensions to reflect the recent miniunit upheavalJeremy Kemper2008-11-071-1/+1
|
* Remove direct TestCase mixins. Add miniunit compatibility.Jeremy Kemper2008-11-071-0/+61