newjs 1.5.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +162 -14
- data/{README.txt → README.rdoc} +1 -1
- data/Rakefile +25 -3
- data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +41 -13
- data/app_generators/newjs_iphone/templates/Html/test/assets/unittest.css +4 -0
- data/features/development.feature +13 -0
- data/features/imported_files_for_generators.feature +19 -0
- data/features/steps/common.rb +205 -0
- data/features/steps/env.rb +6 -0
- data/javascript_test_generators/functional_test/functional_test_generator.rb +9 -1
- data/javascript_test_generators/functional_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/functional_test/templates/test/test.html.erb +15 -1
- data/javascript_test_generators/unit_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/unit_test/templates/test/test.html.erb +18 -20
- data/javascript_test_generators/unit_test/templates/test/test_jshoulda.html.erb +45 -0
- data/javascript_test_generators/unit_test/unit_test_generator.rb +11 -3
- data/lib/newjs.rb +3 -2
- data/newjs_iphone_generators/page/USAGE +5 -0
- data/newjs_iphone_generators/page/page_generator.rb +36 -0
- data/newjs_iphone_generators/page/templates/src/name.css.erb +0 -0
- data/newjs_iphone_generators/page/templates/src/name.html.erb +13 -0
- data/newjs_iphone_generators/page/templates/src/name.js.erb +4 -0
- data/newjs_iphone_generators/page/templates/test/fixtures/name.js.erb +5 -0
- data/newjs_iphone_generators/page/templates/test/unit/name_test.html.erb +61 -0
- data/rack_generators/javascript_test/USAGE +5 -0
- data/rack_generators/javascript_test/javascript_test_generator.rb +88 -0
- data/rack_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rack_generators/javascript_test/templates/assets/jsunittest.js +1004 -0
- data/rack_generators/javascript_test/templates/assets/unittest.css +54 -0
- data/rack_generators/javascript_test/templates/ext/jquery.js +3408 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets → rack_generators/javascript_test/templates/ext}/prototype.js +56 -122
- data/rack_generators/javascript_test/templates/library.js.erb +3 -0
- data/rack_generators/javascript_test/templates/test.html.erb +59 -0
- data/rack_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/rails_generators/javascript_test/javascript_test_generator.rb +15 -3
- data/rails_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rails_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/script/console +10 -0
- data/script/destroy +1 -1
- data/tasks/vendor/update/jshoulda.rake +18 -0
- data/tasks/vendor/update/jsunittest.rake +18 -0
- data/test/test_functional_test_generator.rb +13 -0
- data/test/test_generator_helper.rb +10 -1
- data/test/test_page_generator.rb +50 -0
- data/test/test_rack_javascript_test.rb +166 -0
- data/test/{test_javascript_test_generator.rb → test_rails_javascript_test_generator.rb} +15 -1
- data/test/test_unit_test_generator.rb +13 -0
- data/vendor/jshoulda/History.txt +108 -0
- data/vendor/jshoulda/License.txt +20 -0
- data/vendor/jshoulda/README.mdown +34 -0
- data/vendor/jshoulda/Rakefile +120 -0
- data/vendor/jshoulda/config/javascript_test_autotest.yml.sample +15 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.1.js +62 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.2.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.3.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.1.js +74 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.1.js +110 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.1.js +186 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.js +141 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.x.js +142 -0
- data/vendor/jshoulda/dist/jshoulda.js +186 -0
- data/vendor/jshoulda/jshoulda/test/basic_test.html +42 -0
- data/vendor/jshoulda/lib/jstest.rb +382 -0
- data/vendor/jshoulda/lib/protodoc.rb +36 -0
- data/vendor/jshoulda/script/destroy +14 -0
- data/vendor/jshoulda/script/generate +14 -0
- data/vendor/jshoulda/script/js_autotest +1 -0
- data/vendor/jshoulda/script/rstakeout +97 -0
- data/vendor/jshoulda/site/asset_defaults.yaml +6 -0
- data/vendor/jshoulda/site/config.yaml +3 -0
- data/vendor/jshoulda/site/content/content.html +27 -0
- data/vendor/jshoulda/site/content/content.yaml +4 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.html +268 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.yaml +4 -0
- data/vendor/jshoulda/site/css/blackboard.css +88 -0
- data/vendor/jshoulda/site/css/jshoulda_site.css +33 -0
- data/vendor/jshoulda/site/css/unittest.css +42 -0
- data/vendor/jshoulda/site/example/minimal.html +55 -0
- data/vendor/jshoulda/site/js/editable.js +42 -0
- data/vendor/jshoulda/site/layouts/default/default.html +29 -0
- data/vendor/jshoulda/site/layouts/default/default.yaml +4 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.js +18 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.yaml +4 -0
- data/vendor/jshoulda/site/lib/analytics.rb +12 -0
- data/vendor/jshoulda/site/lib/default.rb +2 -0
- data/vendor/jshoulda/site/lib/example.rb +10 -0
- data/vendor/jshoulda/site/lib/hash.rb +11 -0
- data/vendor/jshoulda/site/lib/highlight.rb +17 -0
- data/vendor/jshoulda/site/page_defaults.yaml +10 -0
- data/vendor/jshoulda/site/templates/default/default.html +1 -0
- data/vendor/jshoulda/site/templates/default/default.yaml +4 -0
- data/vendor/jshoulda/src/HEADER +8 -0
- data/vendor/jshoulda/src/jshoulda.js +177 -0
- data/vendor/jshoulda/src/jshoulda.js.erb +3 -0
- data/vendor/jshoulda/tasks/bundle.rake +12 -0
- data/vendor/jshoulda/tasks/demo.rake +9 -0
- data/vendor/jshoulda/tasks/deploy.rake +29 -0
- data/{tasks → vendor/jshoulda/tasks}/environment.rake +0 -0
- data/vendor/jshoulda/tasks/javascript_test_autotest_tasks.rake +45 -0
- data/vendor/jshoulda/tasks/site.rake +74 -0
- data/vendor/jshoulda/test/assets/jsunittest.js +1004 -0
- data/vendor/jshoulda/test/assets/prototype.js +4324 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets/unittest.js → vendor/jshoulda/test/assets/prototype_unittest.js} +15 -9
- data/vendor/jshoulda/test/assets/unittest.css +50 -0
- data/vendor/jshoulda/test/unit/factory_test.html +82 -0
- data/vendor/jshoulda/test/unit/jshoulda2_test.html +85 -0
- data/vendor/jshoulda/test/unit/jshoulda_prototype_test.html +87 -0
- data/vendor/jshoulda/test/unit/jshoulda_test.html +86 -0
- data/vendor/jshoulda/test/unit/merge_methods_test.html +77 -0
- data/vendor/jshoulda/test/unit/names_and_count.html +68 -0
- data/vendor/jshoulda/test/unit/no_config_test.html +57 -0
- data/vendor/jshoulda/test/unit/styles_test.html +77 -0
- data/vendor/jshoulda/test/unit/unify_runners.html +69 -0
- data/vendor/jshoulda/test/unit/unnamed_context_test.html +67 -0
- data/vendor/jsunittest/Capfile +4 -0
- data/vendor/jsunittest/History.txt +37 -0
- data/{License.txt → vendor/jsunittest/License.txt} +0 -0
- data/vendor/jsunittest/README.txt +21 -0
- data/vendor/jsunittest/Rakefile +118 -0
- data/vendor/jsunittest/config/deploy.rb +20 -0
- data/vendor/jsunittest/config/website.yml.sample +2 -0
- data/vendor/jsunittest/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/dist/unittest.css +54 -0
- data/vendor/jsunittest/lib/jstest.rb +390 -0
- data/vendor/jsunittest/lib/protodoc.rb +36 -0
- data/vendor/jsunittest/script/destroy +14 -0
- data/vendor/jsunittest/script/generate +14 -0
- data/vendor/jsunittest/script/js_autotest +1 -0
- data/vendor/jsunittest/script/rstakeout +97 -0
- data/vendor/jsunittest/script/txt2html +75 -0
- data/vendor/jsunittest/src/HEADER +8 -0
- data/vendor/jsunittest/src/ajax.js +121 -0
- data/vendor/jsunittest/src/assertions.js +244 -0
- data/vendor/jsunittest/src/common.js +191 -0
- data/vendor/jsunittest/src/jsunittest.js +1004 -0
- data/vendor/jsunittest/src/logger.js +86 -0
- data/vendor/jsunittest/src/message_template.js +17 -0
- data/vendor/jsunittest/src/orig/unittest.js +484 -0
- data/vendor/jsunittest/src/prototype/event.js +72 -0
- data/vendor/jsunittest/src/prototype/template.js +33 -0
- data/vendor/jsunittest/src/runner.js +120 -0
- data/vendor/jsunittest/src/test_case.js +106 -0
- data/vendor/jsunittest/tasks/deploy.rake +29 -0
- data/vendor/jsunittest/tasks/environment.rake +7 -0
- data/vendor/jsunittest/tasks/javascript_test_autotest_tasks.rake +44 -0
- data/vendor/jsunittest/tasks/tmbundle.rake +24 -0
- data/vendor/jsunittest/tasks/website.rake +53 -0
- data/vendor/jsunittest/test/assets/example_test.html +50 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/prototype.js +0 -0
- data/vendor/jsunittest/test/assets/unittest.css +54 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/unittest.js +0 -0
- data/vendor/jsunittest/test/functional/jsunittest_test.html +209 -0
- data/vendor/jsunittest/test/unit/assertions_test.html +202 -0
- data/vendor/jsunittest/test/unit/common_test.html +61 -0
- data/vendor/jsunittest/test/unit/logger_test.html +98 -0
- data/vendor/jsunittest/test/unit/message_template_test.html +44 -0
- data/vendor/jsunittest/test/unit/runner_test.html +77 -0
- data/vendor/jsunittest/test/unit/template_test.html +57 -0
- data/vendor/jsunittest/test/unit/test_case_test.html +97 -0
- data/vendor/jsunittest/website/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.tar.gz +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.zip +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/unittest.css +54 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/example_test.html +50 -0
- data/vendor/jsunittest/website/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
- data/vendor/jsunittest/website/images/passing_prototypejs_unittest_tests.jpg +0 -0
- data/vendor/jsunittest/website/index.html +94 -0
- data/vendor/jsunittest/website/index.txt +80 -0
- data/vendor/jsunittest/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/vendor/jsunittest/website/stylesheets/screen.css +138 -0
- data/vendor/jsunittest/website/template.html.erb +46 -0
- data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
- metadata +189 -24
- data/config/hoe.rb +0 -75
- data/config/requirements.rb +0 -17
- data/lib/newjs/version.rb +0 -9
- data/tasks/deployment.rake +0 -34
- data/tasks/jsunittest/update.rake +0 -18
- data/tasks/website.rake +0 -17
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:javascript, :javascript_test, :newjs, :newjs_theme]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:javascript, :javascript_test, :newjs, :newjs_theme]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1 @@
|
|
1
|
+
script/rstakeout "rake test:recent:javascript" test/unit/*_test.html src/*.js
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
|
4
|
+
config = File.dirname(__FILE__) + "/../config/javascript_test_autotest.yml"
|
5
|
+
unless File.exists?(config)
|
6
|
+
puts <<-EOS
|
7
|
+
Edit config/javascript_test_autotest.yml for the browser(s) to use for autotesting.
|
8
|
+
See config/javascript_test_autotest.yml.sample for examples.
|
9
|
+
EOS
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Originally by Mike Clark.
|
15
|
+
#
|
16
|
+
# From http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/StakingOutFileChanges.rdoc
|
17
|
+
#
|
18
|
+
# Runs a user-defined command when files are modified.
|
19
|
+
#
|
20
|
+
# Like autotest, but more customizable. This is useful when you want to do
|
21
|
+
# something other than run tests. For example, generate a PDF book, run
|
22
|
+
# a single test, or run a legacy Test::Unit suite in an app that also
|
23
|
+
# has an rSpec suite.
|
24
|
+
#
|
25
|
+
# Can use Ruby's Dir[] to get file glob. Quote your args to take advantage of this.
|
26
|
+
#
|
27
|
+
# rstakeout 'rake test:recent' **/*.rb
|
28
|
+
# => Only watches Ruby files one directory down (no quotes)
|
29
|
+
#
|
30
|
+
# rstakeout 'rake test:recent' '**/*.rb'
|
31
|
+
# => Watches all Ruby files in all directories and subdirectories
|
32
|
+
#
|
33
|
+
# Modified (with permission) by Geoffrey Grosenbach to call growlnotify for
|
34
|
+
# rspec and Test::Unit output.
|
35
|
+
#
|
36
|
+
# See the PeepCode screencast on rSpec or other blog articles for instructions on
|
37
|
+
# setting up growlnotify.
|
38
|
+
|
39
|
+
def growl(title, msg, img, pri=0, sticky="")
|
40
|
+
system "growlnotify -n autotest --image ~/.autotest_images/#{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.growl_fail(output)
|
44
|
+
growl "FAIL", "#{output}", "fail.png", 2
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.growl_pass(output)
|
48
|
+
growl "Pass", "#{output}", "pass.png"
|
49
|
+
end
|
50
|
+
|
51
|
+
command = ARGV.shift
|
52
|
+
files = {}
|
53
|
+
|
54
|
+
ARGV.each do |arg|
|
55
|
+
Dir[arg].each { |file|
|
56
|
+
files[file] = File.mtime(file)
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "Watching #{files.keys.join(', ')}\n\nFiles: #{files.keys.length}"
|
61
|
+
|
62
|
+
trap('INT') do
|
63
|
+
puts "\nQuitting..."
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
loop do
|
69
|
+
|
70
|
+
sleep 1
|
71
|
+
|
72
|
+
changed_file, last_changed = files.find { |file, last_changed|
|
73
|
+
File.mtime(file) > last_changed
|
74
|
+
}
|
75
|
+
|
76
|
+
if changed_file
|
77
|
+
files[changed_file] = File.mtime(changed_file)
|
78
|
+
puts "=> #{changed_file} changed, running #{command}"
|
79
|
+
results = `#{command}`
|
80
|
+
puts results
|
81
|
+
|
82
|
+
if results.include? 'tests'
|
83
|
+
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
|
84
|
+
if output
|
85
|
+
$~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
|
89
|
+
if output
|
90
|
+
$~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
puts "=> done"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
ENV['rakefile_just_config'] = "true"
|
15
|
+
load File.dirname(__FILE__) + '/../Rakefile'
|
16
|
+
|
17
|
+
version = APP_VERSION
|
18
|
+
download = 'http://rubyforge.org/projects/drnicjavascript'
|
19
|
+
|
20
|
+
class Fixnum
|
21
|
+
def ordinal
|
22
|
+
# teens
|
23
|
+
return 'th' if (10..19).include?(self % 100)
|
24
|
+
# others
|
25
|
+
case self % 10
|
26
|
+
when 1: return 'st'
|
27
|
+
when 2: return 'nd'
|
28
|
+
when 3: return 'rd'
|
29
|
+
else return 'th'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Time
|
35
|
+
def pretty
|
36
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert_syntax(syntax, source)
|
41
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
42
|
+
end
|
43
|
+
|
44
|
+
if ARGV.length >= 1
|
45
|
+
src, template = ARGV
|
46
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
47
|
+
|
48
|
+
else
|
49
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
50
|
+
exit!
|
51
|
+
end
|
52
|
+
|
53
|
+
template = ERB.new(File.open(template).read)
|
54
|
+
|
55
|
+
title = nil
|
56
|
+
body = nil
|
57
|
+
File.open(src) do |fsrc|
|
58
|
+
title_text = fsrc.readline
|
59
|
+
body_text = fsrc.read
|
60
|
+
syntax_items = []
|
61
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
62
|
+
ident = syntax_items.length
|
63
|
+
element, syntax, source = $1, $2, $3
|
64
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
65
|
+
"syntax-temp-#{ident}"
|
66
|
+
}
|
67
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
68
|
+
body = RedCloth.new(body_text).to_html
|
69
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
70
|
+
end
|
71
|
+
stat = File.stat(src)
|
72
|
+
created = stat.ctime
|
73
|
+
modified = stat.mtime
|
74
|
+
|
75
|
+
$stdout << template.result(binding)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/* Jsunittest, version <%= APP_VERSION %>
|
2
|
+
* (c) 2008 Dr Nic Williams
|
3
|
+
*
|
4
|
+
* Jsunittest is freely distributable under
|
5
|
+
* the terms of an MIT-style license.
|
6
|
+
* For details, see the web site: http://jsunittest.rubyforge.org
|
7
|
+
*
|
8
|
+
*--------------------------------------------------------------------------*/
|
@@ -0,0 +1,121 @@
|
|
1
|
+
// A generic function for performming AJAX requests
|
2
|
+
// It takes one argument, which is an object that contains a set of options
|
3
|
+
// All of which are outline in the comments, below
|
4
|
+
// From John Resig's book Pro JavaScript Techniques
|
5
|
+
// published by Apress, 2006-8
|
6
|
+
JsUnitTest.ajax = function( options ) {
|
7
|
+
|
8
|
+
// Load the options object with defaults, if no
|
9
|
+
// values were provided by the user
|
10
|
+
options = {
|
11
|
+
// The type of HTTP Request
|
12
|
+
type: options.type || "POST",
|
13
|
+
|
14
|
+
// The URL the request will be made to
|
15
|
+
url: options.url || "",
|
16
|
+
|
17
|
+
// How long to wait before considering the request to be a timeout
|
18
|
+
timeout: options.timeout || 5000,
|
19
|
+
|
20
|
+
// Functions to call when the request fails, succeeds,
|
21
|
+
// or completes (either fail or succeed)
|
22
|
+
onComplete: options.onComplete || function(){},
|
23
|
+
onError: options.onError || function(){},
|
24
|
+
onSuccess: options.onSuccess || function(){},
|
25
|
+
|
26
|
+
// The data type that'll be returned from the server
|
27
|
+
// the default is simply to determine what data was returned from the
|
28
|
+
// and act accordingly.
|
29
|
+
data: options.data || ""
|
30
|
+
};
|
31
|
+
|
32
|
+
// Create the request object
|
33
|
+
var xml = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
|
34
|
+
|
35
|
+
// Open the asynchronous POST request
|
36
|
+
xml.open(options.type, options.url, true);
|
37
|
+
|
38
|
+
// We're going to wait for a request for 5 seconds, before giving up
|
39
|
+
var timeoutLength = 5000;
|
40
|
+
|
41
|
+
// Keep track of when the request has been succesfully completed
|
42
|
+
var requestDone = false;
|
43
|
+
|
44
|
+
// Initalize a callback which will fire 5 seconds from now, cancelling
|
45
|
+
// the request (if it has not already occurred).
|
46
|
+
setTimeout(function(){
|
47
|
+
requestDone = true;
|
48
|
+
}, timeoutLength);
|
49
|
+
|
50
|
+
// Watch for when the state of the document gets updated
|
51
|
+
xml.onreadystatechange = function(){
|
52
|
+
// Wait until the data is fully loaded,
|
53
|
+
// and make sure that the request hasn't already timed out
|
54
|
+
if ( xml.readyState == 4 && !requestDone ) {
|
55
|
+
|
56
|
+
// Check to see if the request was successful
|
57
|
+
if ( httpSuccess( xml ) ) {
|
58
|
+
|
59
|
+
// Execute the success callback with the data returned from the server
|
60
|
+
options.onSuccess( httpData( xml, options.type ) );
|
61
|
+
|
62
|
+
// Otherwise, an error occurred, so execute the error callback
|
63
|
+
} else {
|
64
|
+
options.onError();
|
65
|
+
}
|
66
|
+
|
67
|
+
// Call the completion callback
|
68
|
+
options.onComplete();
|
69
|
+
|
70
|
+
// Clean up after ourselves, to avoid memory leaks
|
71
|
+
xml = null;
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
// Establish the connection to the server
|
76
|
+
xml.send(null);
|
77
|
+
|
78
|
+
// Determine the success of the HTTP response
|
79
|
+
function httpSuccess(r) {
|
80
|
+
try {
|
81
|
+
// If no server status is provided, and we're actually
|
82
|
+
// requesting a local file, then it was successful
|
83
|
+
return !r.status && location.protocol == "file:" ||
|
84
|
+
|
85
|
+
// Any status in the 200 range is good
|
86
|
+
( r.status >= 200 && r.status < 300 ) ||
|
87
|
+
|
88
|
+
// Successful if the document has not been modified
|
89
|
+
r.status == 304 ||
|
90
|
+
|
91
|
+
// Safari returns an empty status if the file has not been modified
|
92
|
+
navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
|
93
|
+
} catch(e){}
|
94
|
+
|
95
|
+
// If checking the status failed, then assume that the request failed too
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
|
99
|
+
// Extract the correct data from the HTTP response
|
100
|
+
function httpData(r,type) {
|
101
|
+
// Get the content-type header
|
102
|
+
var ct = r.getResponseHeader("content-type");
|
103
|
+
|
104
|
+
// If no default type was provided, determine if some
|
105
|
+
// form of XML was returned from the server
|
106
|
+
var data = !type && ct && ct.indexOf("xml") >= 0;
|
107
|
+
|
108
|
+
// Get the XML Document object if XML was returned from
|
109
|
+
// the server, otherwise return the text contents returned by the server
|
110
|
+
data = type == "xml" || data ? r.responseXML : r.responseText;
|
111
|
+
|
112
|
+
// If the specified type is "script", execute the returned text
|
113
|
+
// response as if it was JavaScript
|
114
|
+
if ( type == "script" )
|
115
|
+
eval.call( window, data );
|
116
|
+
|
117
|
+
// Return the response data (either an XML Document or a text string)
|
118
|
+
return data;
|
119
|
+
}
|
120
|
+
|
121
|
+
};
|
@@ -0,0 +1,244 @@
|
|
1
|
+
JsUnitTest.Unit.Assertions = {
|
2
|
+
buildMessage: function(message, template) {
|
3
|
+
var args = JsUnitTest.arrayfromargs(arguments).slice(2);
|
4
|
+
return (message ? message + '\n' : '') +
|
5
|
+
new JsUnitTest.Unit.MessageTemplate(template).evaluate(args);
|
6
|
+
},
|
7
|
+
|
8
|
+
flunk: function(message) {
|
9
|
+
this.assertBlock(message || 'Flunked', function() { return false });
|
10
|
+
},
|
11
|
+
|
12
|
+
assertBlock: function(message, block) {
|
13
|
+
try {
|
14
|
+
block.call(this) ? this.pass() : this.fail(message);
|
15
|
+
} catch(e) { this.error(e) }
|
16
|
+
},
|
17
|
+
|
18
|
+
assert: function(expression, message) {
|
19
|
+
message = this.buildMessage(message || 'assert', 'got <?>', expression);
|
20
|
+
this.assertBlock(message, function() { return expression });
|
21
|
+
},
|
22
|
+
|
23
|
+
assertEqual: function(expected, actual, message) {
|
24
|
+
message = this.buildMessage(message || 'assertEqual', 'expected <?>, actual: <?>', expected, actual);
|
25
|
+
this.assertBlock(message, function() { return expected == actual });
|
26
|
+
},
|
27
|
+
|
28
|
+
assertNotEqual: function(expected, actual, message) {
|
29
|
+
message = this.buildMessage(message || 'assertNotEqual', 'expected <?>, actual: <?>', expected, actual);
|
30
|
+
this.assertBlock(message, function() { return expected != actual });
|
31
|
+
},
|
32
|
+
|
33
|
+
assertEnumEqual: function(expected, actual, message) {
|
34
|
+
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
|
35
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
36
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
37
|
+
this.assertBlock(message, function() {
|
38
|
+
if (expected_array.length == actual_array.length) {
|
39
|
+
for (var i=0; i < expected_array.length; i++) {
|
40
|
+
if (expected_array[i] != actual_array[i]) return false;
|
41
|
+
};
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
return false;
|
45
|
+
});
|
46
|
+
},
|
47
|
+
|
48
|
+
assertEnumNotEqual: function(expected, actual, message) {
|
49
|
+
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
|
50
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
51
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
52
|
+
this.assertBlock(message, function() {
|
53
|
+
if (expected_array.length == actual_array.length) {
|
54
|
+
for (var i=0; i < expected_array.length; i++) {
|
55
|
+
if (expected_array[i] != actual_array[i]) return true;
|
56
|
+
};
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
return true;
|
60
|
+
});
|
61
|
+
},
|
62
|
+
|
63
|
+
assertHashEqual: function(expected, actual, message) {
|
64
|
+
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
|
65
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
66
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
67
|
+
var block = function() {
|
68
|
+
if (expected_array.length == actual_array.length) {
|
69
|
+
for (var i=0; i < expected_array.length; i++) {
|
70
|
+
if (expected_array[i] != actual_array[i]) return false;
|
71
|
+
};
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
return false;
|
75
|
+
};
|
76
|
+
this.assertBlock(message, block);
|
77
|
+
},
|
78
|
+
|
79
|
+
assertHashNotEqual: function(expected, actual, message) {
|
80
|
+
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
|
81
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
82
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
83
|
+
// from now we recursively zip & compare nested arrays
|
84
|
+
var block = function() {
|
85
|
+
if (expected_array.length == actual_array.length) {
|
86
|
+
for (var i=0; i < expected_array.length; i++) {
|
87
|
+
if (expected_array[i] != actual_array[i]) return true;
|
88
|
+
};
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
return true;
|
92
|
+
};
|
93
|
+
this.assertBlock(message, block);
|
94
|
+
},
|
95
|
+
|
96
|
+
assertIdentical: function(expected, actual, message) {
|
97
|
+
message = this.buildMessage(message || 'assertIdentical', 'expected <?>, actual: <?>', expected, actual);
|
98
|
+
this.assertBlock(message, function() { return expected === actual });
|
99
|
+
},
|
100
|
+
|
101
|
+
assertNotIdentical: function(expected, actual, message) {
|
102
|
+
message = this.buildMessage(message || 'assertNotIdentical', 'expected <?>, actual: <?>', expected, actual);
|
103
|
+
this.assertBlock(message, function() { return expected !== actual });
|
104
|
+
},
|
105
|
+
|
106
|
+
assertNull: function(obj, message) {
|
107
|
+
message = this.buildMessage(message || 'assertNull', 'got <?>', obj);
|
108
|
+
this.assertBlock(message, function() { return obj === null });
|
109
|
+
},
|
110
|
+
|
111
|
+
assertNotNull: function(obj, message) {
|
112
|
+
message = this.buildMessage(message || 'assertNotNull', 'got <?>', obj);
|
113
|
+
this.assertBlock(message, function() { return obj !== null });
|
114
|
+
},
|
115
|
+
|
116
|
+
assertUndefined: function(obj, message) {
|
117
|
+
message = this.buildMessage(message || 'assertUndefined', 'got <?>', obj);
|
118
|
+
this.assertBlock(message, function() { return typeof obj == "undefined" });
|
119
|
+
},
|
120
|
+
|
121
|
+
assertNotUndefined: function(obj, message) {
|
122
|
+
message = this.buildMessage(message || 'assertNotUndefined', 'got <?>', obj);
|
123
|
+
this.assertBlock(message, function() { return typeof obj != "undefined" });
|
124
|
+
},
|
125
|
+
|
126
|
+
assertNullOrUndefined: function(obj, message) {
|
127
|
+
message = this.buildMessage(message || 'assertNullOrUndefined', 'got <?>', obj);
|
128
|
+
this.assertBlock(message, function() { return obj == null });
|
129
|
+
},
|
130
|
+
|
131
|
+
assertNotNullOrUndefined: function(obj, message) {
|
132
|
+
message = this.buildMessage(message || 'assertNotNullOrUndefined', 'got <?>', obj);
|
133
|
+
this.assertBlock(message, function() { return obj != null });
|
134
|
+
},
|
135
|
+
|
136
|
+
assertMatch: function(expected, actual, message) {
|
137
|
+
message = this.buildMessage(message || 'assertMatch', 'regex <?> did not match <?>', expected, actual);
|
138
|
+
this.assertBlock(message, function() { return new RegExp(expected).exec(actual) });
|
139
|
+
},
|
140
|
+
|
141
|
+
assertNoMatch: function(expected, actual, message) {
|
142
|
+
message = this.buildMessage(message || 'assertNoMatch', 'regex <?> matched <?>', expected, actual);
|
143
|
+
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
|
144
|
+
},
|
145
|
+
|
146
|
+
assertHasClass: function(element, klass, message) {
|
147
|
+
element = JsUnitTest.$(element);
|
148
|
+
message = this.buildMessage(message || 'assertHasClass', '? doesn\'t have class <?>.', element, klass);
|
149
|
+
this.assertBlock(message, function() {
|
150
|
+
return !!element.className.match(new RegExp(klass))
|
151
|
+
});
|
152
|
+
},
|
153
|
+
|
154
|
+
assertHidden: function(element, message) {
|
155
|
+
element = JsUnitTest.$(element);
|
156
|
+
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
|
157
|
+
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
|
158
|
+
},
|
159
|
+
|
160
|
+
assertInstanceOf: function(expected, actual, message) {
|
161
|
+
message = this.buildMessage(message || 'assertInstanceOf', '<?> was not an instance of the expected type', actual);
|
162
|
+
this.assertBlock(message, function() { return actual instanceof expected });
|
163
|
+
},
|
164
|
+
|
165
|
+
assertNotInstanceOf: function(expected, actual, message) {
|
166
|
+
message = this.buildMessage(message || 'assertNotInstanceOf', '<?> was an instance of the expected type', actual);
|
167
|
+
this.assertBlock(message, function() { return !(actual instanceof expected) });
|
168
|
+
},
|
169
|
+
|
170
|
+
assertRespondsTo: function(method, obj, message) {
|
171
|
+
message = this.buildMessage(message || 'assertRespondsTo', 'object doesn\'t respond to <?>', method);
|
172
|
+
this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function') });
|
173
|
+
},
|
174
|
+
|
175
|
+
assertRaise: function(exceptionName, method, message) {
|
176
|
+
message = this.buildMessage(message || 'assertRaise', '<?> exception expected but none was raised', exceptionName);
|
177
|
+
var block = function() {
|
178
|
+
try {
|
179
|
+
method();
|
180
|
+
return false;
|
181
|
+
} catch(e) {
|
182
|
+
if (e.name == exceptionName) return true;
|
183
|
+
else throw e;
|
184
|
+
}
|
185
|
+
};
|
186
|
+
this.assertBlock(message, block);
|
187
|
+
},
|
188
|
+
|
189
|
+
assertNothingRaised: function(method, message) {
|
190
|
+
try {
|
191
|
+
method();
|
192
|
+
this.assert(true, "Expected nothing to be thrown");
|
193
|
+
} catch(e) {
|
194
|
+
message = this.buildMessage(message || 'assertNothingRaised', '<?> was thrown when nothing was expected.', e);
|
195
|
+
this.flunk(message);
|
196
|
+
}
|
197
|
+
},
|
198
|
+
|
199
|
+
_isVisible: function(element) {
|
200
|
+
element = JsUnitTest.$(element);
|
201
|
+
if(!element.parentNode) return true;
|
202
|
+
this.assertNotNull(element);
|
203
|
+
if(element.style && (element.style.display == 'none'))
|
204
|
+
return false;
|
205
|
+
|
206
|
+
return arguments.callee.call(this, element.parentNode);
|
207
|
+
},
|
208
|
+
|
209
|
+
assertVisible: function(element, message) {
|
210
|
+
message = this.buildMessage(message, '? was not visible.', element);
|
211
|
+
this.assertBlock(message, function() { return this._isVisible(element) });
|
212
|
+
},
|
213
|
+
|
214
|
+
assertNotVisible: function(element, message) {
|
215
|
+
message = this.buildMessage(message, '? was not hidden and didn\'t have a hidden parent either.', element);
|
216
|
+
this.assertBlock(message, function() { return !this._isVisible(element) });
|
217
|
+
},
|
218
|
+
|
219
|
+
assertElementsMatch: function() {
|
220
|
+
var pass = true, expressions = JsUnitTest.arrayfromargs(arguments);
|
221
|
+
var elements = expressions.shift();
|
222
|
+
if (elements.length != expressions.length) {
|
223
|
+
message = this.buildMessage('assertElementsMatch', 'size mismatch: ? elements, ? expressions (?).', elements.length, expressions.length, expressions);
|
224
|
+
this.flunk(message);
|
225
|
+
pass = false;
|
226
|
+
}
|
227
|
+
for (var i=0; i < expressions.length; i++) {
|
228
|
+
var expression = expressions[i];
|
229
|
+
var element = JsUnitTest.$(elements[i]);
|
230
|
+
if (JsUnitTest.selectorMatch(expression, element)) {
|
231
|
+
pass = true;
|
232
|
+
break;
|
233
|
+
}
|
234
|
+
message = this.buildMessage('assertElementsMatch', 'In index <?>: expected <?> but got ?', index, expression, element);
|
235
|
+
this.flunk(message);
|
236
|
+
pass = false;
|
237
|
+
};
|
238
|
+
this.assert(pass, "Expected all elements to match.");
|
239
|
+
},
|
240
|
+
|
241
|
+
assertElementMatches: function(element, expression, message) {
|
242
|
+
this.assertElementsMatch([element], expression);
|
243
|
+
}
|
244
|
+
};
|