Skip to content

Instantly share code, notes, and snippets.

@hamajyotan
Last active December 23, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamajyotan/6681517 to your computer and use it in GitHub Desktop.
Save hamajyotan/6681517 to your computer and use it in GitHub Desktop.
バッククォートでのシステムコマンド実行が呼び出されることを RSpec で検証する 追記: $? の値が任意であることを検証する方法を追加
# -*- 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
@hamajyotan
Copy link
Author

exitstatus と、標準出力の結果を検証するように変更

@hamajyotan
Copy link
Author

よく考えれば標準出力については単純に返り値で良いのでシンプルに

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment