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