Why is my controller acting different in the rspec execution than in the browser execution? <p>I have my controller:</p> <pre><code>class Api::BunknotesController &lt; Api::ApiController # ... omitted code def show @bunknote = current_user.bunknotes.includes(:person).find(params[:id]) respond_to do |format| format.html { render layout: false } format.pdf { render pdf: @bunknote.filename, template: '/bunknotes/show.pdf', margin: { top: 5, bottom: 5 } byebug } format.json { render json: @bunknote.api_json(true) } end end # ... omitted code end </code></pre> <p>In the second format, Wicked PDF is used to render. The rendered template looks like this:</p> <pre><code>&lt;%= wicked_pdf_stylesheet_link_tag "bunknotes" %&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;div class="page &lt;% if @bunknote.reply %&gt;pagebreak&lt;% end %&gt; bunknote_pdf"&gt; &lt;div class="bn-id"&gt;bn&lt;%= @bunknote.id %&gt;&lt;/div&gt; &lt;h1&gt;Bunk Note to &lt;%= @bunknote.person ? @bunknote.person.name : @bunknote.writein %&gt; &lt;%= "(#{@bunknote.address})" if @bunknote.address &amp;&amp; @bunknote.address.length &gt; 1 %&gt;&lt;/h1&gt; &lt;%= render partial: 'details', locals: { :bunknote =&gt; @bunknote } %&gt; &lt;/div&gt; &lt;% if @bunknote.reply %&gt; &lt;div class="page bunkreply-stationery"&gt; &lt;%= render partial: '/common/stationery', locals: { user_fullname: @bunknote.user.fullname, org_name: @bunknote.organization.name, org_id: @bunknote.organization.id, user_id: @bunknote.user.id, bunknote_id: "bn#{@bunknote.id}", barcode_value: "#{has_bunknote = 1}#{@bunknote.id}", height: "720px", camper_name: @bunknote.person ? @bunknote.person.name : @bunknote.writein } %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>When I try to hit my controller, I have a template error. The error's nature is like this: Inside my show.pdf.erb template, which is /bunknotes/show.pdf.erb, I am referencing the file 'details'. Since my controller is <code>Api::BunknotesController</code> (there is another controller named <code>BunknotesController</code>, without prefix, which had a copy of this template in first place), the relative inclusion would try to find the file in /app/views/api/bunknotes/ instead of /app/views/bunknotes.</p> <p>By trying to hit it in my browser, I get a 500 when trying to render the pdf, and the <code>byebug</code> instruction is not reached (as anyone could expect when having any exception out of the special purpose ones in rails like <code>RecordInvalid</code> and so). Due to other internals, the generated pdf is corrupt on this scenario (something we will fix later but for now it serves as a good sign that something did not go well).</p> <p><strong>However a pretty different behavior is triggered when running a test</strong></p> <p>My test file looks like:</p> <pre><code># ... omitted code describe Api::BunknotesController do # ... omitted code it "gets a bunknote (PDF)" do get :show, {id: bunknote1.id, format: :pdf} expect(response.status).to be 200 end # ... omitted code end # ... omitted code </code></pre> <p>When the rspec utility runs this example, A blank pdf (non-corrupt, but totally blank) is generated by the controller, and a 200 response code is returned.</p> <p>I made this test to succeed for a 200 code if things got well. The test should have failed when the show view misreferenced (for my needs) the inner view. But instead it succeeded, seeming to absorb the error like a diaper, and generating the blank PDF file. I expect that this behave exactly as the browser call, generate the corrupt pdf, returns a 500 code, and fails.</p> <p><strong>Summary</strong>:</p> <ol> <li>Yes, I will fix the path to the included view so it is absolute.</li> <li>Yes, I will fix the corrupt pdf generation so that no pdf attachment files are ever sent.</li> <li>The test should not have succeeded as it did. The test is expected to succeed only if the response code is 200. This is right, but the controller produced a 200 in the rspec execution, while returning a 500 in the browser execution.</li> </ol> <p>Why is my controller acting different in the rspec execution than in the browser execution?</p> <p>I am using:</p> <ul> <li>Ruby 2.3.0p0</li> <li>Rails 3.2.22.2</li> <li>RSpec 3.4.1</li> </ul>