title: Rspec testing methods in transaction
body: <p>I am trying to execute two things inside a transaction and I'm not sure how I should test it in rspec. My code looks something like this:</p>
  
  <p>Implementation:</p>
  
  <pre><code>    def method
        begin
          ActiveRecord::Base.transaction do
            ...some implementation...
            model1.save!
            model2.save!
          end
        rescue =&gt; e
            exception_info = {:class =&gt; e.class, :message =&gt; e.message, :backtrace =&gt; e.backtrace}
            @logger.warn("Error. Rolling back.", :exception =&gt; exception_info)
        end
      end
  </code></pre>
  
  <p>Tests:</p>
  
  <pre><code>it "model1 object is not created if model2 fails to save" do
    Model1.any_instance.should_receive(:save).and_raise("model1 save error!!")
    method
    Model2.all.should == []
  end
  
  it "" do
    Model2.any_instance.should_receive(:save).and_raise("model2 save error!!")
    method
    Model1.all.should == []
  end
  </code></pre>
  
  <p>I want both the models to be saved or none. My rspec tests check both the cases but I keep getting errors. If I add (:requires_new => true) to the transaction, it works. I thought it was meant for nested transactions, not something like this. Am I missing something?</p>