title: How to create test data in rspec
body: <p>Hi i am working on rails app with ruby-2.5.0 and Rails 5. I have to test my forgot_password controller there is a method which validates if the email id is presnt in the database or not.</p>
  
  <pre><code>forgot_password_controller.rb
  # frozen_string_literal: true
  
  class ForgotPasswordController &lt; ApplicationController
  
      def create
          user = User.find_by_email(forgot_password_params[:email])
          unless user.blank?
        render json: {}, status: 200
      else
        render json: {}, status: 404
      end
    rescue StandardError
      render json: {}, status: 500
    end
  
      private
  
    def forgot_password_params
      permitted = %i[email]
      params.require(:data)
            .require(:attributes)
            .permit(permitted)
            .transform_keys(&amp;:underscore)
    end
  end
  </code></pre>
  
  <p>I want to test my api. i have written unit testing as follows:-</p>
  
  <pre><code>forgot_password_controller_spec.rb
  # frozen_string_literal: true
  
  require 'rails_helper'
  
  describe ForgotPasswordController do
    before do
      User.create!(email: 'xyz@gmail.com',
                   password: 'pass',
                   password_confirmation: 'pass')
    end
  
    describe 'POST create' do
      subject { post :create, params: params }
  
      context 'when email is found' do
        let(:params) do
          { data: { attributes: { email: 'xyz@gmail.com' } } }
        end
  
        it { is_expected.to have_http_status(200) }
      end
  
      context 'when email is not found' do
        let(:params) do
          { data: { attributes: { email: 'xyz2@gmail.com' } } }
        end
  
        it { is_expected.to have_http_status(404) }
      end
  
      context 'when wrong params passed' do
        let(:params) do
          { data: '' }
        end
  
        it { is_expected.to have_http_status(500) }
      end
    end
  end
  </code></pre>
  
  <p>Now i want to create test data with 'let'
   like  </p>
  
  <pre><code>let(:user) { instance_double('user') }
  let(:save_result) { true }
  </code></pre>
  
  <p>How can i create user with let please help me. Thanks in advance.</p>