• U
    Add method_call_assertions and use them instead of Mocha · a72bca82
    utilum 提交于
    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]
    a72bca82
method_call_assertions.rb 2.4 KB