2
系统调用这是帮助模块:嘲讽/磕碰使用RSPEC
module SendingMailHelper
def send_mail(subject, body)
to_email_id = " [email protected]"
cc_email_id = "[email protected]"
html_message = %{<html><body>#{body}</body></html>}
flag=false
while(!flag) do
flag = system %{echo "#{html_message}" | mutt -e "set content_type=text/html" -s "#{subject}" #{cc_email_id} -- #{to_email_id}}
end
flag
end
end
我写我的规格的方式是如下,但它不工作:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe SendingMailHelper do
it "test something" do
html_message = %{<html><body>www.google.com</body></html>}
to_email_id = " [email protected]"
cc_email_id = "[email protected]"
subject = "test e-mail"
SendingMailHelper.expects(:system).with(%{echo "#{html_message}" | mutt -e "set content_type=text/html" -s "#{subject}" #{cc_email_id} -- #{to_email_id}}).returns(true).once
helper.send_mail("test e-mail","www.google.com").should==true
end
end
收到以下错误:
SendingMailHelper test something
Failure/Error: SendingMailHelper.expects(:system).with(%{echo "#{html_message}" | mutt -e "set content_type=text/html" -s "#{subject}" #{cc_email_id} -- #{to_email_id}}).returns(true).once
Mocha::ExpectationError:
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked:
我也想嘲笑它以这样的方式嘲弄狗返回false
两次,并在第三次调用中测试重试机制。有没有办法做到这一点?
试试'Kernel.expects(:system)...' – BroiSatse
我该如何解决上述测试案例? – user1280282