我有以下代碼你如何使用測試代碼叉rspec的
def start_sunspot_server
unless @server
pid = fork do
STDERR.reopen("/dev/null")
STDOUT.reopen("/dev/null")
server.run
end
at_exit { Process.kill("TERM", pid) }
wait_until_solr_starts
end
end
我將如何有效地去使用RSpec的測試呢?
我想的東西沿
Kernel.should_receive(:fork)
STDERR.should_receive(:reopen).with("/dev/null")
STDOUT.should_receive(:reopen).with("/dev/null")
server.should_receive(:run)
等
如果我嘲笑對象(使用'expect'匹配器),但如果我使用'allow'匹配器來存根對象(stub)時可以使它工作,我就無法使它工作。如果存根未被調用,則測試不會失敗,但您將在輸出中看到錯誤。建議通過指定它應該接收的參數來使存根特定。 – Dennis 2016-07-20 13:26:34