Skip to content
  • bogdanvlviv's avatar
    9d0cf520
    `assert_called_with` should require `args` argument · 9d0cf520
    bogdanvlviv authored
    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
    9d0cf520
    `assert_called_with` should require `args` argument
    bogdanvlviv authored
    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
Loading