title: Rspec: Creating user before testing method
body: <p>Hi I am new to rspec (and unit testing in general) and want to test the following method:</p>
  
  <pre><code>class HelloController &lt; ApplicationController
  
    def hello_world
      user = User.find(4)
      @subscription = 10.00
      render :text =&gt; "Done."
    end
  end
  </code></pre>
  
  <p>I am trying to use Rspec like so:</p>
  
  <pre><code>Describe HelloController, :type =&gt; :controller do
  
      describe "get hello_world" do
  
        it "should render the text 'done'" do
          get :hello_world
          expect(response.body).to include_text("Done.")
        end
      end
    end
  </code></pre>
  
  <p>I would like to simply test that the method works properly and renders the test "done". I get the following error when I run the test:</p>
  
  <pre><code> Failure/Error: user = User.find(4)
  
   ActiveRecord::RecordNotFound:
     Couldn't find User with 'id'=4
  </code></pre>
  
  <p>But how do I properly create a user with that id before executing it? I have tried the following  based on other tutorials and questions but it doesn't work:</p>
  
  <pre><code>describe "get hello_world" do
          let(:user) {User.create(id: 4)}
  
              it "should render the text 'done'" do
                  get :hello_world
                  expect(response.body).to include_text("Done.")
              end
      end
  </code></pre>
  
  <p>Thank you in advance.</p>