我的serverspec示例,使用serverspec-init进行设置,然后我生成了这个简单的测试文件./spec/altspf01/sample_spec.rb
require 'spec_helper'
describe command( '/bin/hostname -s' ) do
its(:stdout) { should match /atlspf01/ }
end
我希望它能ssh到远程主机(atlspf01)并检查其主机名(atlspf01)。相反,它连接到localhost(ltipc682)。
1) Command "/bin/hostname -s" stdout should match /atlspf01/
Failure/Error: its(:stdout) { should match /atlspf01/ }
expected "ltipc682\n" to match /atlspf01/
Diff:
@@ -1,2 +1,2 @@
-/atlspf01/
+ltipc682
我做错了什么?
此处的所有代码:https://gist.github.com/neilhwatson/a3f4a26ad8cf27d62307
答案 0 :(得分:3)
Serverspec的规范应该通过rake
运行。否则,规范不知道目标主机。
但是,如果您希望通过rspec
运行它,则可以使用此解决方法:
env TARGET_HOST='atlspf01' rspec spec/atlspf01/sample_spec.rb
希望这有帮助。