问题
I am trying to configure jasmine.yml (using jasmine gem) to use JQuery served from Google API instead of downloading it locally to my server. I.e.:
src_files:
- ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
Unfortunately this does not seem to work, since (as per the comments in the config file) it is looking for filepaths relative to src_dir. Is this not possible then?
Thanks
Ruy
回答1:
I ended up writing the javascript include via spec helper - in my case the Livereload script:
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>');
It’s a bit hacky but works. You might want to define more accurately where the script is being inserted.
回答2:
If you are using the jasmine-rails gem you can create your own layouts/jasmine_rails/spec_runner.html
, and add the remote dependency there.
!!! 5
%html
%head
%title Jasmine Specs
= stylesheet_link_tag *jasmine_css_files
%script(src='//maps.googleapis.com/maps/api/js?sensor=false')
= javascript_include_tag *jasmine_js_files
%body
#jasmine_content
= yield
回答3:
You can use jQuery getScript:
$.getScript( external_script_url, function( data, textStatus, jqxhr ) {
some code to execute after script is loaded
});
In case you also want to include jQuery externally, you have to load it this way
document.write('<script src="http://.../jquery.min.js</script>')
来源:https://stackoverflow.com/questions/7681151/is-there-a-way-to-include-external-javascript-as-a-source-to-jasmine