无法加载rspec配置

时间:2015-09-28 09:33:03

标签: ruby-on-rails ruby-on-rails-4 rspec-rails

尝试在linux机器上运行rspec spec/controllers/api_controller_spec.rb:406 --color命令时。我们已经在端口6379上运行了redis服务器但是如下错误无法加载rspec spec_helper配置&得到错误:

代码:

 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 ]
------------
------------
------------

1 个答案:

答案 0 :(得分:0)

重新启动redis服务器redis-server stop/start。生成的redis.pid文件和​​rspec能够在后台处理期间访问redis配置。