title: Expect the creation of a new object
body: <p>I need to write an expectation that a new object will be created in a payment system. Code included from <code>order.rb</code> and <code>order_spec.rb</code> (<code>Order</code> class is <a href="https://github.com/benhawker/ruby-order-processing/blob/master/lib/order.rb" rel="noreferrer">here</a>):</p>
  
  <pre><code>#order.rb 
  
  def confirm_order(method_of_payment)
    if credit_card_but_products_out_stock?(method_of_payment)
      raise "Cannot make credit card payment now, as some products are out of stock" 
    end
  
    order_total
    Payment.new(method_of_payment, self.total)
  end
  
  #order_spec.rb
  
  it 'it creates a new payment object if method_of_payment is valid and order.total is &gt; 0' do
    order.add_product(product, 3)
    order.confirm_order(:credit_card)
    #Expect that a new payment object is created.
  end
  </code></pre>
  
  <p>I want to understand how I can write the appropriate spec to test that the new Payment object is created. I found <a href="https://semaphoreci.com/community/tutorials/mocking-with-rspec-doubles-and-expectations" rel="noreferrer">this article</a> from Semaphore CI useful, but am not sure about a solution. I am pretty sure I should be creating a test double of some sort, and then maybe a method stub to <code>allow(order).to receive(:confirm_order).and_return(#new_object??)</code>.</p>