如何使用Rubymotion测试api没有超时异常

时间:2014-12-28 06:16:56

标签: ruby tdd rubymotion

我正在使用Rubymotion并尝试为API方法编写测试,例如。

it "should call the api and return a result" do
   Omapi.now do |response|
     response.should.be.kind_of(Hash)
     resume
   end
   wait {}
end

和我正在调用的方法

def now(&callback)           
  AFMotion::JSON.get(MY_URL) do |result|
    callback.call result
  end
end

我是使用AFMotion,Elevate还是Bubblewrap,还是使用不同的公开测试端点 - 我总是有相同的响应。即。 api正确返回结果,但测试失败,无论如何都有超时错误。

#<AFMotion::HTTPResult:0x10d43e460 @operation=#<AFHTTPRequestOperation:0x114415c60> @object=[{"result"=>"ok"}] @error=nil>

[失败 - 超时超时:omapi - 应该调用api]

培根::错误:超时超时:omapi - 应该调用api spec.rb:404:在block in postponed_block_timeout_exceeded': omapi - should call the api spec.rb:459:in execute_block'中 spec.rb:404:在`postponed_block_timeout_exceeded'

有没有办法增加错误引用的超时?

由于

1 个答案:

答案 0 :(得分:0)

尝试使用wait_max帮助程序。

it "should call the api and return a result" do
  Omapi.now do |response|
    response.should.be.kind_of(Hash)
    resume
  end
  wait_max 20.0 {} # 20 seconds maximum
end