1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

15 commits

Author SHA1 Message Date
bogdanvlviv
9d0cf52096
assert_called_with should require args argument
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 - a970ecc42c
2018-10-25 21:29:39 +03:00
Kasper Timm Hansen
9136bb77a7
Merge pull request #33162 from utilum/stop_using_mocha
Stop using Mocha
2018-08-22 18:20:25 +02:00
bogdanvlviv
88439585ed
Test assert_called and assert_called_with
- 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
2018-08-14 09:01:01 +03:00
utilum
a72bca8230 Add method_call_assertions and use them instead of Mocha
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]
2018-08-13 13:05:14 +02:00
bogdanvlviv
ad59b71b80
Remove extra include ActiveSupport::Testing::MethodCallAssertions
It includes via `require "abstract_unit"`.
2018-06-08 23:59:56 +03:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Ronak Jangir
63a70ad6ff Cleaned up generators tests using internal assertion helper 2015-08-20 09:22:56 +05:30
Ronak Jangir
e49c2cd743 Replacing lambda with proc getting argument error because of it. 2015-08-17 20:28:00 +05:30
Ronak Jangir
bfe7532876 Added helper methods to stub any instance 2015-08-13 08:32:35 +05:30
Kasper Timm Hansen
46b92c4d12 Add multiple expected calls to assert_called_with. 2015-07-10 23:45:42 +02:00
Kasper Timm Hansen
53f64c0fb2 Add method call assertions for internal use.
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.
2015-07-08 21:15:27 +02:00