Je suis en train de tester certaines librairies javascript que j'ai construites en utilisant harmony de ruby. Tout fonctionne parfaitement sauf les appels AJAX - est-ce que quelqu'un a des idées pour y parvenir?Tests unitaires asynchrones en Ruby
Mon code ressemble à ceci (j'utilise RightJS):
my.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_makerequest.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
Alors oui, mon question est, comment dois-je attribuer results
ci-dessus de telle sorte que je peux obtenir la res ults du rappel asynchrone?