title: How to test a hard coded class using a fake in MiniTest
body: <p>I have a <code>PlantTree</code> job that calls a <code>PlantTree</code> service object. I would like to test the job to ascertain that it instantiates the <code>PlantTree</code> service with a <code>tree</code> argument and calls the <code>call</code> method.</p>
  
  <p>I'm not interested in what the service does or the result. It has its own tests, and I don't want to repeat those tests for the job.</p>
  
  <pre><code># app/jobs/plant_tree_job.rb
  class PlantTreeJob &lt; ActiveJob::Base
    def perform(tree)
      PlantTree.new(tree).call
    end
  end
  
  # app/services/plant_tree.rb
  class PlantTree
    def initialize(tree)
      @tree = tree
    end
  
    def call
      # Do stuff that plants the tree
    end
  end
  </code></pre>
  
  <p>As you can see, the <code>PlantTree</code> class is hard coded in the <code>perform</code> method of the job. So I can't fake it and pass it in as a dependency. Is there a way I can fake it for the life time of the perform method? Something like...</p>
  
  <pre><code>class PlantTreeJobTest &lt; ActiveJob::TestCase
    setup do
      @tree = create(:tree)
    end
  
    test "instantiates PlantTree service with `@tree` and calls `call`" do
      # Expectation 1: PlantTree will receive `new` with `@tree`
      # Expectation 2: PlatTree will receive `call`
      PlantTreeJob.perform_now(@tree)
      # Verify that expections 1 and 2 happened.
    end
  end
  </code></pre>
  
  <p>I'm using Rails' default stack, which uses MiniTest. I know this can be done with Rspec, but I'm only interested in MiniTest. If it's not possible to do this with MiniTest only, or the default Rails stack, I'm open to using an external library.</p>