nginx -vでの出力はstderrを指定すれば、テストが通るというメモを記す。
nginx -vで、nginxのバージョンを確認する。
1 2 |
出力結果: nginx version: nginx/1.4.6 (Ubuntu) |
“stdout”では失敗する。
1 2 3 4 5 6 |
// nginx_spec.rb # Check installed package version describe command("nginx -v") do its(:exit_status) { should eq 0 } its(:stdout) { should match /1.4.6/ } end |
1 2 3 4 5 |
テスト結果: 1) Command "nginx -v" stdout should match /1.4.6/ On host `melody` Failure/Error: its(:stdout) { should match /1.4.6/ } expected "" to match /1.4.6/ |
“stderr”にすると成功する。
1 2 3 4 5 6 |
// nginx_spec.rb # Check installed package version describe command(`nginx -v`) do its(:exit_status) { should eq 0 } its(:stderr) { should match /1.4.6/ } end |
1 2 3 4 5 6 7 8 |
テスト結果: Command "nginx -v" exit_status should eq 0 stderr should match /1.4.6/ Finished in * seconds (files took * seconds to load) 2 examples, 0 failures |
どうやらnginxの仕様らしい。
Why write nginx version on stderr?
gccやjavaも同じ類のようである。