How to verify json response in controller tests?
<p>I have a rails controller that returns only json</p>

<pre><code>def index
  if params[:filtered] = 'someValue'
    @json = Model.where(some_conditions).to_json 
  else
    @json = Model.where(some_other_conditions).to_json 
  end
  render json: @json
end
</code></pre>

<p>What is the correct way to test that the action is returning the expected @json objects?</p>

<p>I've tried the following </p>

<pre><code>describe "GET #index" do  
  before :each do
    get :index, filtered: 'someValue'
  end
  it { expect( response.body ).to eq 'my expected response' }
end
</code></pre>

<p>But I'm getting </p>

<pre><code>Failure/Error: it { expect( response.body ).to eq 'my expected response' }
expected: 'my expected response'
got: "[]"
</code></pre>

<p>I'm having trouble determining whether there is a problem in the underlying controller, or whether I've simply written a bad test. </p>

<p>Is <code>response.body</code> the correct way to get the json payload?</p>

<p>Help appreciated! </p>