aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/testing
Commit message (Collapse)AuthorAgeFilesLines
* `assert_called_with` should require `args` argumentbogdanvlviv2018-10-251-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | There are two main reasons why `assert_called_with` should require `args` argument: 1) If we want to assert that some method should be called and we don't need to check with which arguments it should be called then we should use `assert_called`. 2) `assert_called_with` without `args` argument doesn't assert anything! ```ruby assert_called_with(@object, :increment) do @object.decrement end ``` It causes false assertions in tests that could cause regressions in the project. I found this bug by working on [minitest-mock_expectations](https://github.com/bogdanvlviv/minitest-mock_expectations) gem. This gem is an extension for minitest that provides almost the same method call assertions. I was wondering whether you would consider adding "minitest-mock_expectations" to `rails/rails` instead of private `ActiveSupport::Testing::MethodCallAssertions` module. If yes, I'll send a patch - https://github.com/bogdanvlviv/rails/commit/a970ecc42c3a9637947599f2c13e3762e4b59208
* Merge pull request #33162 from utilum/stop_using_mochaKasper Timm Hansen2018-08-221-0/+83
|\ | | | | Stop using Mocha
| * Add method_call_assertions and use them instead of Mochautilum2018-08-131-0/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Six Mocha calls prove quite resistant to Minitestification. For example, if we replace ``` ActiveRecord::Associations::HasManyAssociation .any_instance .expects(:reader) .never ``` with `assert_not_called`, Minitest wisely raises ``` NameError: undefined method `reader' for class `ActiveRecord::Associations::HasManyAssociation' ``` as `:reader` comes from a deeply embedded abstract class, `ActiveRecord::Associations::CollectionAssociation`. This patch tackles this difficulty by adding `ActiveSupport::Testing::MethodCallAsserts#assert_called_on_instance_of` which injects a stubbed method into `klass`, and verifies the number of times it is called, similar to `assert_called`. It also adds a convenience method, `assert_not_called_on_instance_of`, mirroring `assert_not_called`. It uses the new method_call_assertions to replace the remaining Mocha calls in `ActiveRecord` tests. [utilum + bogdanvlviv + kspath]
* | Test `assert_called` and `assert_called_with`bogdanvlviv2018-08-141-0/+10
|/ | | | | | | | - ActiveSupport::Testing::MethodCallAssertions#assert_called - Ensure that the method stubbed by `assert_called` returns correct value after - ActiveSupport::Testing::MethodCallAssertions#assert_called_with - Ensure that `#assert_called_with` stubs the method to return a specific value - Ensure that the method stubbed by `assert_called_with` returns correct value after
* Remove extra `include ActiveSupport::Testing::MethodCallAssertions`bogdanvlviv2018-06-081-3/+0
| | | | It includes via `require "abstract_unit"`.
* `SetupAndTeardown` has few caveats that breaks libraries:Edouard CHIN2018-04-271-3/+5
| | | | | | | | | | | | | | | | | | - In #32472 I introduced a fix in order for all `after_teardown` method provided by libraries and Rails to run, even if the application's `teardown` method raised an error (That's the default minitest behavior). However this change wasn't enough and doesn't take in consideration the ancestors chain. If a library's module containing an `after_teardown` method get included after the `SetupAndTeardown` module (one example is the [ActiveRecord::TestFixtures module](https://github.com/rails/rails/blob/7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4/activerecord/lib/active_record/fixtures.rb#L855-L856), then the ancestors of the test class would look something like ```ruby class MyTest < ActiveSupport::TestCase end puts MyTest.ancestors # [MyTest, ActiveSupport::TestCase, ActiveRecord::TestFixtures, ActiveSupport::Testing::SetupAndTeardown] ``` Any class/module in the ancestors chain that are **before** the `ActiveSupport::Testing::SetupAndTeardown` will behave incorrectly: - Their `before_setup` method will get called **after** all regular setup method - Their `after_teardown` method won't even get called in case an exception is raised inside a regular's test `teardown` A simple reproduction script of the problem here https://gist.github.com/Edouard-chin/70705542a59a8593f619b02e1c0a188c - One solution to this problem is to have the `AS::SetupAndTeardown` module be the very first in the ancestors chain. By doing that we ensure that no `before_setup` / `after_teardown` get executed prior to running the teardown callbacks
* Rename the class as there is already an existing class with that nameEdouard CHIN2018-04-061-1/+1
|
* `SetupAndTeardown#teardown` should call any subsequent after_teardown:Edouard CHIN2018-04-061-0/+34
| | | | | | | | If you have a regular test that have a teardown block, and for any reason an exception get raised, ActiveSupport will not run subsequent after_teardown method provided by other module or gems. One of them being the ActiveRecord::TestFixtures which won't rollback the transation when the test ends making all subsequent test to be in a weird state. The default implementation of minitest is to run all teardown methods from the user's test, rescue all exceptions, run all after_teardown methods provided by libraries and finally re-raise the exception that happened in the user's teardown method. Rails should do the same.
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-113-0/+3
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-093-0/+3
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-023-3/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-013-0/+3
|
* Define path with __dir__bogdanvlviv2017-05-231-2/+2
| | | | | | ".. with __dir__ we can restore order in the Universe." - by @fxn Related to 5b8738c2df003a96f0e490c43559747618d10f5f
* Should escape meta characters in regexpRyuta Kamizono2017-05-071-2/+2
|
* applies new string literal convention in activesupport/testXavier Noria2016-08-063-8/+8
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Pathname might not be always initialized.Vít Ondruch2016-07-041-0/+2
| | | | Require 'pathname' explicitly
* Do not depend on Rails git repository layout in ActiveSupport tests.Vít Ondruch2016-07-011-2/+2
|
* Cleaned up generators tests using internal assertion helperRonak Jangir2015-08-201-0/+6
|
* Replacing lambda with proc getting argument error because of it.Ronak Jangir2015-08-171-0/+6
|
* Added helper methods to stub any instanceRonak Jangir2015-08-131-0/+13
|
* Add multiple expected calls to assert_called_with.Kasper Timm Hansen2015-07-101-0/+7
|
* Add method call assertions for internal use.Kasper Timm Hansen2015-07-081-0/+91
| | | | | Add `assert_called` and `assert_not_called` to boil down the boilerplate we need to write to assert methods are called certain number of times.
* introduce `ActiveSupport::Testing::FileFixtures`.Yves Senn2015-01-281-0/+28
| | | | | | It's a thin layer to provide easy access to sample files throughout test-cases. This adds the directory `test/fixtures/files` to newly generated applications.
* Use `safe_constantize`.Guo Xiang Tan2014-09-021-0/+8
| | | | Fixes https://github.com/rails/rails/issues/9933.
* Unused classes in AS testsAkira Matsuda2013-12-191-1/+0
|
* determine_constant_from_test_name does not swallow NoMethodErrors [Yves Senn]Xavier Noria2013-03-281-0/+10
|
* extract PerformanceTest into rails-performance_tests gemYves Senn2013-01-101-68/+0
|
* Fix typo in test nameCarlos Antonio da Silva2012-11-041-1/+1
|
* some ruby interpreters don't have ruby-prof so just skip the testsAaron Patterson2012-10-181-3/+12
| | | | rather than exiting the process.
* ConstantLookup is not needed in every TestCase decendantAndy Lindeman2012-09-261-0/+1
|
* Add missing inflector dependencyMike Moore2012-09-251-1/+1
|
* Create ActiveSupport::Testing::ConstantLookupMike Moore2012-09-241-0/+58
| | | | | AS::TC::ConstantLookup walks the test's name to find the constant it is describing. This additional lookup logic is needed to better support minitest's spec DSL.
* Eliminate dependency on Rails::VERSION::STRINGAndrew White2012-06-051-2/+21
| | | | | | To facilitate the use of ActiveSupport::Testing::Performance outside of a Rails application conditionally check for the presence of Rails::VERSION::STRING before including it in the environment string.
* decoupling activesupport performance testing from actionview and adding testsAndrew Mutz2012-05-281-0/+40