【发布时间】:2011-07-17 18:56:58
【问题描述】:
这里是 TDD 新手,哦!
简而言之,这是我要测试的内容 (ruby library):
account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN)
resp = account.request(
"/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/SMS/Messages",
'POST',
smsInfo
)
这里是测试代码尝试:
describe Text do
it "should call the Twilio API with credentials" do
#pending "mocking api although not passed in.."
t = mock(Twilio::RestAccount)
twapi = mock("new twapi").should_receive(:request).and_return(Net::HTTPSuccess)
t.stub(:new).and_return(twapi)
Twilio::RestAccount.should_receive(:new)
sms = Factory.create(:boring_sms)
sms.send_sms
end
end
产生错误:nil:NilClass 的未定义方法 `request'
我是否采取了正确的方法?谢谢!
【问题讨论】:
标签: testing rspec mocking twilio