我正在测试我使用 ruby 的Harmony构建的一些 javascript 库。除了 AJAX 调用外,一切都运行良好——有人知道如何实现这一点吗?
我的代码看起来像这样(我正在使用RightJS):
我的.js
function makerequest(argument) {
new Xhr('http://mysite.com/some/jsonp'),{
jsonp: true,
params: {something: argument},
onSuccess: function() {
// Calls a function defined outside my library
parse_response(this.json)
}
}).send()
}
test_makerrequest.rb
require 'rubygems'
require 'harmony'
require 'test/unit'
require 'shoulda'
class RequestTest < Test::Unit::TestCase
context "The requesty thing" do
setup do
@page = Harmony::Page.new
@page.load(File.expand_path('js/my.js'))
end
should "get stuff from mysite.com" do
# Here I need to define a 'parse_response' which this
# should section will wait for and then do an 'assert'
# on the results.
results = callback_to_get_results_from__make_request
@page.execute('make_request("an argument")')
assert results == {'foo' => 'bar'}
end
end
end
所以是的,我的问题是,我应该如何results
在上面进行分配,以便我可以获得异步回调的结果?