【发布时间】:2015-11-06 12:54:52
【问题描述】:
我认为这个问题可能与serverspec service test returns incorrect failure 重复,但我提供了更多关于我的执行环境的信息。
我在 AWS 上针对 RHEL6 虚拟机执行了一系列成功的 serverspec 测试。
但是,任何“服务”测试似乎都因匹配器 be_enabled 和 be_running 而失败。
我的 spec_helper.rb 中有以下内容:
set :os, :family => 'redhat', :release => '6', :arch => 'x86_64'
我为测试尝试了 serverspec 和 rspec 语法,但都失败了,因为它们运行相同的命令:
describe service('ntpd') do
it { should be_enabled }
it { should be_running }
end
it "is running ntpd" do
expect(service("ntpd")).to be_enabled
expect(service("ntpd")).to be_running
end
Failure/Error: it { should be_enabled }
expected Service "ntpd" to be enabled
sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ ntpd\ \|\ grep\ 3:on
Failure/Error: it { should be_running }
expected Service "ntpd" to be running
sudo -p 'Password: ' /bin/sh -c service\ ntpd\ status
但是,在服务器上本地运行它们会成功:
$ sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ ntpd\ \|\ grep\ 3:on
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ echo $?
0
$ sudo -p 'Password: ' /bin/sh -c service\ ntpd\ status
ntpd (pid 1101) is running...
$ echo $?
0
我尝试使用 pry-byebug 设置一些调试,但这看起来不太简单,所以我暂时放弃了。
我正在运行 ruby 2.0、serverspec 2.24、rspec 3.3
谁能帮我指出正确的方向?
【问题讨论】:
标签: ruby testing service rspec serverspec