我有一个围绕AFMotion建立的模型。当我尝试使用WebStub测试http标头时,测试陷入僵局。我试图通过将我的模型从等式中移除并仅使用WebStub和AFMotion编写测试来隔离问题。我能想到的最好的就是这个。
describe AFMotion::JSON do
extend WebStub::SpecHelpers
describe "#get" do
it "includes headers" do
stub = stub_request(:get, "http://localhost/test").
to_return(json: {foo: 'bar'})
stub.with_callback do |headers, _|
headers.kind_of?(Hash).should == true
end
client = AFMotion::JSON.get("http://localhost/test") do
resume
end
wait { }
end
end
end
这可以避免死锁,但是不会调用存根回调
#get
- includes headers [MISSING - empty specification: #get includes headers]
Bacon::Error: empty specification: #get includes headers
spec.rb:437:in `block in finish_spec': #get - includes headers
spec.rb:459:in `execute_block'
spec.rb:437:in `finish_spec'
spec.rb:427:in `run_postponed_block:'
spec.rb:416:in `resume'
有没有什么方法可以测试AFMotion标头而不会死锁?