【问题标题】:Checking if a hidden file exists with Serverspec使用 Serverspec 检查是否存在隐藏文件
【发布时间】:2014-06-23 19:42:18
【问题描述】:

我正在使用 Test-Kitchen 和 Serverspec 进行集成测试。我想使用 Serverspec 文件资源来验证是否存在隐藏文件,在本例中为 .gemrc。这是我的规格配置:

require 'spec_helper'

describe "Checking the .gemrc" do  

  describe file('~/.gemrc') do
    it { should be_file }
  end
end

这是错误输出:

       Check .gemrc
         File "~/.gemrc"
    should be file (FAILED - 1)       

Failures:       

  1) Check .gemrc File "~/.gemrc" should be file       
     Failure/Error: it { should be_file }       
       test -f \~/.gemrc       
       expected file? to return true, got false       
     # /tmp/busser/suites/serverspec/default/ruby_spec.rb:14:in `block (3 levels) in <top (required)>'       

Finished in 0.06349 seconds       
1 example, 1 failure

为什么file 资源没有将 .gemrc 文件视为普通文件?

【问题讨论】:

  • 文件真的存在吗?
  • 是的,文件存在。
  • 并且用户可读你能显示目录的ls -al 吗?

标签: ruby integration-testing hidden-files dotfiles test-kitchen


【解决方案1】:

~ 简写是许多流行的 shell 支持的路径扩展,但它不是真正的文件系统路径。实际上,您是在要求文件资源在名为 ~ 的实际子目录中查找文件 .gemrc(来自未指定的工作目录,无论它在规范运行时可能是什么)。

我认为您需要指定文件的绝对路径(例如,file('/home/username/.gemrc'))。

【讨论】:

    猜你喜欢
    • 2020-05-22
    • 1970-01-01
    • 2022-01-04
    • 2012-01-19
    • 1970-01-01
    • 2023-03-12
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多