title: How do I create an rspec test that validates a JSON response?
body: <p>I have a Groups Controller with a method <code>def inbox.</code></p>
  
  <p>If the user is a group member then inbox returns a JSON object.</p>
  
  <p>If the user is not a member, then inbox should redirect thanks to CanCan permissions.</p>
  
  <p>How do I write an rspec to test these two use cases?</p>
  
  <p>Current spec:</p>
  
  <pre><code>require 'spec_helper'
  
  describe GroupsController do
    include Devise::TestHelpers
  
    before (:each) do
      @user1 = Factory.create(:user)
      @user1.confirm!
      sign_in @user1
      @group = Factory(:group)
      @permission_user_1 = Factory.create(:permission, :user =&gt; @user1, :creator_id =&gt; @user1.id, :group =&gt; @group)
    end
  
    describe "GET inbox" do
      it "should be successful" do
        get inbox_group_path(@group.id), :format =&gt; :json
        response.should be_success
      end
    end
  end
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>inbox_group GET /groups/:id/inbox(.:format) {:controller=&gt;"groups", :action=&gt;"inbox"}
  </code></pre>
  
  <p>Routes File:</p>
  
  <pre><code>resources :groups do
    member do
      get 'vcard', 'inbox'
    end
    ....
  end
  </code></pre>