Please sign in to comment.
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]
- Loading branch information...
Showing with 170 additions and 36 deletions.
- +3 −2 activerecord/test/cases/associations/eager_test.rb
- +20 −12 activerecord/test/cases/associations/has_many_associations_test.rb
- +0 −2 activerecord/test/cases/helper.rb
- +35 −20 activerecord/test/cases/tasks/database_tasks_test.rb
- +29 −0 activesupport/lib/active_support/testing/method_call_assertions.rb
- +83 −0 activesupport/test/testing/method_call_assertions_test.rb