title: Trying to change environment variable within RSpec model spec
body: <p>I've got one User model which has different validations based on an environmental variable ENV['APP_FOR']. This can either be "app-1" or "app-2". app-1 validates for username while app-2 validates for email address. Here is my User model spec for app-1: </p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe User, type: :model do
  
    include Shared::Categories
  
    before do
      ENV['APP_FOR']='app-1'
    end
  
    context "given a valid User" do
      before { allow_any_instance_of(User).to receive(:older_than_18?).and_return(true) }
  
      it {should validate_presence_of :username}
    end
  end 
  </code></pre>
  
  <p>And this is the User model spec for app-2</p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe User, type: :model do
  
    include Shared::Categories
  
    before do
      ENV['APP_FOR']='app-2'
    end
  
    context "given a valid User" do
      before { allow_any_instance_of(User).to receive(:older_than_18?).and_return(true) }
  
      it {should validate_presence_of :email}
    end
  end
  </code></pre>
  
  <p>My problem is that the environment variable isn't being set as I would expect it to be in the before block. Any ideas on how to do this?</p>
  
  <p>EDIT 1</p>
  
  <p>Here is my validation implementation. I used a concern which I extend the user model with: </p>
  
  <pre><code>module TopDogCore::Concerns::UserValidations
    extend ActiveSupport::Concern
    included do
  
      if ENV['APP_FOR'] == 'app-1'
        validates :username,
                  presence: true,
                  uniqueness: true        
  
      elsif ENV['APP_FOR'] == 'app-2'
        validates :email, 
                  presence: true,
                  uniqueness: true
      end
    end
  end
  </code></pre>