Setting ActiveRecord::Errors object to nil <p>I am trying to add unit tests to a part of my project that deals with displaying errors.</p> <p>In order to test for correct handling in a case where there is no ActiveRecord::Errors object to iterate through, I am trying to delete the errors object (not the individual errors) from an otherwise-working test fixture (<code>@customer</code>).</p> <p>I had hoped <code>@customer.errors = nil</code> would do the job, but it is raising an error.</p> <p>Test case:</p> <pre><code> test "Errors_WhenErrorsObjectNotFound_RaisesNoErrors" do log_in_as(@customer) @customer.errors = nil get :edit, id: @customer assert_nothing_raised end </code></pre> <p>Unit being tested (should not be relevant but just in case):</p> <pre><code>&lt;% if errors.count == 0 || errors.nil? %&gt; &lt;div class="success"&gt; &lt;ul&gt; &lt;li&gt;Update successful&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% else %&gt; &lt;div class="error"&gt; &lt;ul&gt; &lt;% errors.full_messages.each do |err| %&gt; &lt;li&gt;&lt;%= err %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Error generated:</p> <pre><code> 3) Error: CustomersControllerTest#test_Errors_WhenErrorsObjectNotFound_RaisesNoErrors: NoMethodError: undefined method `errors=' for #&lt;Customer:0x9b0f958&gt; test/controllers/customers_controller_test.rb:184:in `block in &lt;class:CustomersControllerTest&gt;' </code></pre> <p>Any suggestions on how to delete the errors object?</p>