title: How do I resolve "bad argument (expected URI object or URI string)"? Ruby on Rails, Michael Hartl Tutorial
body: <p>I'm following the <a href="http://ruby.railstutorial.org/" rel="nofollow">Ruby on Rails Tutorial</a> by Michael Hartl.</p>
  
  <p>I reached <a href="http://ruby.railstutorial.org/chapters/following-users#code-relationships_controller_spec_ajax" rel="nofollow">Chapter 11.37</a> but my test is failing. I get the following error: </p>
  
  <pre><code>Failure/Error: xhr :post, :create, relationship: { followed_id: other_user.id }
  ArgumentError:
  bad argument (expected URI object or URI string)
  </code></pre>
  
  <p>I'm new to Ruby on Rails so I don't really know what's going wrong. Can someone help resolve this error? </p>
  
  <p>controllers/relationships_controller.rb:</p>
  
  <pre><code>class RelationshipsController &lt; ApplicationController
    before_action :signed_in_user
  
    def create
      @user = User.find(params[:relationship][:followed_id])
      current_user.follow!(@user)
      respond_to do |format|
        format.html { redirect_to @user }
        format.js
      end
    end
  
    def destroy
      @user = Relationship.find(params[:id]).followed
      current_user.unfollow!(@user)
      respond_to do |format|
        format.html { redirect_to @user }
        format.js
      end
    end
  end
  </code></pre>
  
  <p>features/relationships_controller_spec.rb:</p>
  
  <pre><code>require 'spec_helper'
  
  describe RelationshipsController, type: :request do
  
    let(:user) { FactoryGirl.create(:user) }
    let(:other_user) { FactoryGirl.create(:user) }
  
    before { sign_in user, no_capybara: true }
  
    describe "creating a relationship with Ajax" do
  
      it "should increment the Relationship count" do
        expect do
          xhr :post, :create, relationship: { followed_id: other_user.id }
        end.to change(Relationship, :count).by(1)
      end
  
      it "should respond with success" do
        xhr :post, :create, relationship: { followed_id: other_user.id }
        expect(response).to be_success
      end
    end
  
    describe "destroying a relationship with Ajax" do
  
      before { user.follow!(other_user) }
      let(:relationship) { user.relationships.find_by(followed_id: other_user) }
  
      it "should decrement the Relationship count" do
        expect do
          xhr :delete, :destroy, id: relationship.id
        end.to change(Relationship, :count).by(-1)
      end
  
      it "should respond with success" do
        xhr :delete, :destroy, id: relationship.id
        expect(response).to be_success
      end
    end
  end
  </code></pre>