title: Rails Request Rspec Jbuilder, request.body is a StringIO object
body: <p>I'm working on a project in Ruby on Rails, and I decided to use Jbuilder for handling the json serialization of my models. However when using Rspec to test my controllers with request specs, using the <code>*.json.jbuilder</code> views, my <code>request.body</code> comes back as a <code>StringIO</code> object, not a <code>String</code>.</p>
  
  <p>My method in the affected controller looks like:</p>
  
  <pre><code>def list
    @groups = ...
  end
  </code></pre>
  
  <p>And the <code>list.json.jbuilder</code> file looks like:</p>
  
  <pre><code>json.array! @groups, :id, :name
  </code></pre>
  
  <p>The test snippet looks like:</p>
  
  <pre><code>get '/api/v1/groups', { :format =&gt; :json }
  puts request.body.class.name # gives StringIO instead of String...
  </code></pre>
  
  <p>I'm using Rails 4.2.2, Ruby 2.2.2, Rspec-Rails 3.3.2 and JBuilder 2.3.0</p>
  
  <p>I have set in my <code>rails_helper.rb</code>:</p>
  
  <pre><code>config.render_views # tried with config.render_views = true too
  </code></pre>
  
  <p>The stacktrace for the exception is:</p>
  
  <pre><code>Failure/Error: expect(json['groups'].length).to eq (2)
   TypeError:
     no implicit conversion of StringIO into String
  </code></pre>
  
  <p>I can add that it <em>works</em> when not using Rspec.</p>
  
  <p>Thanks</p>