我有以下代码你如何使用测试代码叉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