2015-09-28 104 views
0

試圖在linux計算機上運行rspec spec/controllers/api_controller_spec.rb:406 --color命令。我們已經Redis的服務器運行在端口6379但如下錯誤無法加載rspec的spec_helper配置&收到錯誤:無法加載rspec配置

代碼:

REDIS_PID = "/var/run/redis.pid" 
    REDIS_CACHE_PATH = "tmp/cache/" 

    Dir.mkdir "#{Rails.root}/tmp" unless Dir.exists? "#{Rails.root}/tmp" 
    Dir.mkdir "#{Rails.root}/tmp/pids" unless Dir.exists? "#{Rails.root}/tmp/pids" 
    Dir.mkdir "#{Rails.root}/tmp/cache" unless Dir.exists? "#{Rails.root}/tmp/cache" 

    config.before(:suite) do 
    redis_options = { 
     "daemonize"  => 'yes', 
     "pidfile"  => 7528, 
     "port"   => 6379, 
     "timeout"  => 300, 
     "save 900"  => 1, 
     "save 300"  => 1, 
     "save 60"  => 10000, 
     "dbfilename" => "dump.rdb", 
     "dir"   => REDIS_CACHE_PATH, 
     "loglevel"  => "debug", 
     "logfile"  => "stdout", 
     "databases"  => 16 
    }.map { |k, v| "#{k} #{v}" }.join("\n") 
    `echo '#{redis_options}' | redis-server -` 
    end 

    config.after(:suite) do 
    %x{ 
     cat #{REDIS_PID} | xargs kill -QUIT 
     rm -f #{REDIS_CACHE_PATH}dump.rdb 
    } 
    end 

錯誤:

------------ 
------------ 
------------ 

Finished searching in 0.09762763977050781 seconds. 
Request#<ActionController::TestRequest:0x00000004139f58> 
^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2cFcat: /var/run/redis.pid: No such file or directory 
usage: kill [ -s signal | -p ] [ -a ] pid ... 
     kill -l [ signal ] 
------------ 
------------ 
------------ 
+0

'/ var/run/redis.pid'確實存在嗎?對於rspec運行,您是否可以更好地嘲笑Redis進行更安全的測試? – glenatron

+0

請找到下面的答案。 –

回答

0

重新啓動redis服務器redis-server stop/start。生成的redis.pid文件和​​rspec能夠在後臺處理期間訪問redis配置。

相關問題