Last active
December 23, 2015 19:19
-
-
Save hamajyotan/6681517 to your computer and use it in GitHub Desktop.
バッククォートでのシステムコマンド実行が呼び出されることを RSpec で検証する 追記: $? の値が任意であることを検証する方法を追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
class Hoge | |
def moe | |
`ls -l` | |
end | |
end | |
describe "hoge" do | |
let(:hoge) { Hoge.new } | |
it do | |
# hoge.should_receive(:`).with("ls -l").and_return { `echo "echo moemoe; exit 3" | sh` } | |
hoge.should_receive(:`).with("ls -l").and_return do | |
`echo "exit 3" | sh` | |
"moemoe\n" | |
end | |
expect(hoge.moe).to be == "moemoe\n" | |
expect($?.exitstatus).to be == 3 | |
end | |
end |
よく考えれば標準出力については単純に返り値で良いのでシンプルに
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exitstatus と、標準出力の結果を検証するように変更