title: An error occurred while loading ./spec/controllers/users_controller_spec.rb
body: <p>I am creating factories to replace my fixtures and to generate Test Data. I've installed FactoryBot but I am getting an error when running "rspec". This is the outcome log I get:</p>
  
  <pre><code>An error occurred while loading ./spec/controllers/users_controller_spec.rb.
  Failure/Error: @user = FactoryBot.create(:user)
  
  ActiveRecord::RecordInvalid:
    Validation failed: Email has already been taken
  # ./spec/controllers/users_controller_spec.rb:5:in `block in &lt;top (required)&gt;'
  # ./spec/controllers/users_controller_spec.rb:3:in `&lt;top (required)&gt;'
  
  
  Finished in 0.00041 seconds (files took 38.38 seconds to load)
  0 examples, 0 failures, 1 error occurred outside of examples
  </code></pre>
  
  <p>This is my spec/factories/user_factory.rb</p>
  
  <pre><code>FactoryBot.define do
    factory :user do
      email "peter@example.com"
      password "0123456"
      first_name "Peter"
      last_name "Example"
      admin false
    end
  end
  </code></pre>
  
  <p>This is my spec/controllers/users_controller_spec.rb</p>
  
  <pre><code>require 'rails_helper'
  
  describe UsersController, type: :controller do
  
    @user = FactoryBot.create(:user)
  
    # let (:user) { User.create!(email:"achochaocierva@gmail.com", password: "Ratadecierva2")}
  
    describe 'GET #show' do
        context 'when a user is logged in' do
          before do
            sign_in user
          end
          it 'loads correct user details' do
               get :show, params: { id: user.id }
               expect(response).to be_ok
               expect(assigns(:user)).to eq user
            end
          end
  
        context 'when a user is not logged in' do
          it 'redirects to login' do
            get :show, params: { id: user.id }
            expect(response).to redirect_to(new_user_session_path)
         end
      end
    end
  end
  </code></pre>
  
  <p>What would be the errors meaning? What am I doing wrong?</p>