这里是 TDD 的新手,哦!
简而言之,这是我要测试的内容(ruby 库):
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 的未定义方法“请求”
我是否采取了正确的方法?谢谢!