title: Rspec - uninitialized constant RAILS_ENV
body: <p>I run my task crate db:restore and display error:</p>
  
  <pre><code>** Execute db:restore
  rake aborted!
  NameError: uninitialized constant RAILS_ENV
  /home/dima/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.5.2/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
  /home/dima/myapp/bdsmgalaxy/lib/tasks/mysql.rake:24:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>My task is :</p>
  
  <pre><code>require 'yaml'
  
  namespace :db do
      def backup_prep
      @directory = File.join(RAILS_ROOT, 'db', 'backup')
      @db = YAML::load( File.open( File.join(RAILS_ROOT, 'config', 'database.yml') ) )[ RAILS_ENV ]
      @db_params = "-u #{@db['username']} #{@db['database']}"
      @db_params = "-p#{@db['password']} #{@db_params}" unless @db['password'].blank?
    end
  
    desc 'Backup database by mysqldump'
    task :backup =&gt; :environment do
      backup_prep
      FileUtils.mkdir @directory unless File.exists?(@directory)
      file = File.join( @directory, "#{RAILS_ENV}_#{DateTime.now.to_s}.sql" )
      command = "mysqldump #{@db_params} | gzip &gt; #{file}.gz" #--opt --skip-add-locks 
      puts "dumping to #{file}..."
      # p command
      exec command
    end
  
    desc "restore most recent mysqldump (from db/backup/*.sql.*) into the current environment's database."
    task :restore =&gt; :environment do
      unless RAILS_ENV=='development'      
        puts "Are you sure you want to import into #{RAILS_ENV}?! [y/N]"
        return unless STDIN.gets =~ /^y/i
      end
      backup_prep
      wildcard  = File.join( @directory, ENV['FILE'] || "#{ENV['FROM']}*.sql*" )
      puts file = `ls -t #{wildcard} | head -1`.chomp  # default to file, or most recent ENV['FROM'] or just plain most recent
      if file =~ /\.gz(ip)?$/
        command = "gunzip &lt; #{file} | mysql #{@db_params}"
      else
        command = "mysql #{@db_params} &lt; #{file}"
      end
      p command
      puts "please wait, this may take a minute or two..."
      exec command
    end
  end
  </code></pre>
  
  <p>How to solve this problem?</p>