raus22-jspec 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +323 -0
- data/Manifest +44 -0
- data/README.rdoc +495 -0
- data/Rakefile +72 -0
- data/bin/jspec +137 -0
- data/jspec.gemspec +35 -0
- data/lib/images/bg.png +0 -0
- data/lib/images/hr.png +0 -0
- data/lib/images/loading.gif +0 -0
- data/lib/images/sprites.bg.png +0 -0
- data/lib/images/sprites.png +0 -0
- data/lib/images/vr.png +0 -0
- data/lib/jspec.css +145 -0
- data/lib/jspec.jquery.js +64 -0
- data/lib/jspec.js +1468 -0
- data/server/browsers.rb +16 -0
- data/server/server.rb +103 -0
- data/spec/async +1 -0
- data/spec/jquery-1.3.1.js +4241 -0
- data/spec/server.html +23 -0
- data/spec/spec.grammar-less.js +34 -0
- data/spec/spec.grammar.js +179 -0
- data/spec/spec.html +27 -0
- data/spec/spec.jquery.js +166 -0
- data/spec/spec.js +119 -0
- data/spec/spec.matchers.js +382 -0
- data/spec/spec.rhino.js +12 -0
- data/spec/spec.shared-behaviors.js +51 -0
- data/spec/spec.utils.js +138 -0
- data/templates/default/History.rdoc +4 -0
- data/templates/default/README.rdoc +29 -0
- data/templates/default/lib/yourlib.core.js +2 -0
- data/templates/default/spec/spec.core.js +8 -0
- data/templates/default/spec/spec.html +20 -0
- data/templates/rhino/History.rdoc +4 -0
- data/templates/rhino/README.rdoc +29 -0
- data/templates/rhino/lib/yourlib.core.js +2 -0
- data/templates/rhino/spec/spec.core.js +8 -0
- data/templates/rhino/spec/spec.js +7 -0
- data/templates/server/History.rdoc +4 -0
- data/templates/server/README.rdoc +29 -0
- data/templates/server/lib/yourlib.core.js +2 -0
- data/templates/server/spec/spec.core.js +8 -0
- data/templates/server/spec/spec.html +15 -0
- metadata +120 -0
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
def version
|
7
|
+
$1 if File.read('lib/jspec.js').match /version *: *'(.*?)'/
|
8
|
+
end
|
9
|
+
|
10
|
+
Echoe.new "jspec", version do |p|
|
11
|
+
p.author = "TJ Holowaychuk"
|
12
|
+
p.email = "tj@vision-media.ca"
|
13
|
+
p.summary = "JavaScript BDD Testing Framework"
|
14
|
+
p.url = "http://visionmedia.github.com/jspec"
|
15
|
+
p.runtime_dependencies << "visionmedia-commander >=3.2.9"
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :pkg do
|
19
|
+
desc 'Build package'
|
20
|
+
task :build => ['pkg:clear'] do
|
21
|
+
begin
|
22
|
+
sh 'mkdir pkg'
|
23
|
+
sh 'cp -fr lib/* pkg'
|
24
|
+
minify 'lib/jspec.js', 'pkg/jspec.min.js'
|
25
|
+
minify 'lib/jspec.jquery.js', 'pkg/jspec.jquery.min.js'
|
26
|
+
compress 'lib/jspec.css', 'pkg/jspec.min.css'
|
27
|
+
sh 'git add pkg/.'
|
28
|
+
rescue Exception => e
|
29
|
+
puts "Failed to package: #{e}."
|
30
|
+
else
|
31
|
+
puts "Packaging of JSpec-#{version} completed."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Clear packaging'
|
36
|
+
task :clear do
|
37
|
+
if File.directory? 'pkg'
|
38
|
+
sh 'rm -fr pkg/*'
|
39
|
+
sh 'rmdir pkg'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Display compression savings of last release'
|
44
|
+
task :savings do
|
45
|
+
totals = Hash.new { |h, k| h[k] = 0 }
|
46
|
+
format = '%-20s : %0.3f kb'
|
47
|
+
totals = %w( pkg/jspec.min.js pkg/jspec.jquery.min.js pkg/jspec.min.css ).inject totals do |total, file|
|
48
|
+
uncompressed = File.size(file.sub('.min', '')).to_f / 1024
|
49
|
+
compressed = File.size(file).to_f / 1024
|
50
|
+
saved = uncompressed - compressed
|
51
|
+
puts format % [file.sub('pkg/', ''), saved]
|
52
|
+
totals[:saved] += saved
|
53
|
+
totals[:uncompressed] += uncompressed
|
54
|
+
totals[:compressed] += compressed
|
55
|
+
totals
|
56
|
+
end
|
57
|
+
puts
|
58
|
+
puts format % ['total uncompressed', totals[:uncompressed]]
|
59
|
+
puts format % ['total compressed', totals[:compressed]]
|
60
|
+
puts format % ['total saved', totals[:saved]]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def minify from, to
|
65
|
+
sh "jsmin < #{from} > #{to}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def compress from, to
|
69
|
+
File.open(to, 'w+') do |file|
|
70
|
+
file.write File.read(from).gsub(/(^[\t ]*)|\n/, '')
|
71
|
+
end
|
72
|
+
end
|
data/bin/jspec
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
JSPEC_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
$:.unshift JSPEC_ROOT
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'commander'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
RHINO = 'java org.mozilla.javascript.tools.shell.Main'
|
11
|
+
program = {}
|
12
|
+
program[:name] => 'JSpec'
|
13
|
+
program[:version] => '2.0.3'
|
14
|
+
program[:description] => 'JavaScript BDD Testing Framework'
|
15
|
+
default_command :bind
|
16
|
+
|
17
|
+
command :init do |c|
|
18
|
+
c.syntax = 'jspec init [dest]'
|
19
|
+
c.summary = 'Initialize a JSpec project template'
|
20
|
+
c.description = 'Initialize a JSpec project template. Defaults to the current directory
|
21
|
+
when [dest] is not specified. Currently three templates are available:
|
22
|
+
|
23
|
+
"default" : runs specs in browser(s) using the DOM formatter.
|
24
|
+
"rhino" : runs specs with Rhino using the Terminal formatter.
|
25
|
+
"server" : runs specs using a Ruby server/client solution which
|
26
|
+
starts each browser and reports back to the terminal.'
|
27
|
+
c.example 'Create a directory foo, initialized with a jspec template', 'jspec init foo'
|
28
|
+
c.example 'Initialize a rhino based project in the current directory', 'jspec init --template rhino'
|
29
|
+
c.example 'Initialize a server based project in foo', 'jspec init foo --template server'
|
30
|
+
c.option '-T', '--template name', 'Template to use. Valid choices are default, rhino, and server.'
|
31
|
+
c.when_called do |args, options|
|
32
|
+
dest = args.shift || '.'
|
33
|
+
options.default :template => 'default'
|
34
|
+
unless Dir[dest + '/*'].empty?
|
35
|
+
abort unless agree "'#{dest}' is not empty; continue? "
|
36
|
+
end
|
37
|
+
template = File.join JSPEC_ROOT, 'templates', options.template, '.'
|
38
|
+
abort "template #{options.template} does not exist" unless File.exists? template
|
39
|
+
FileUtils.mkdir_p dest
|
40
|
+
FileUtils.cp_r template, dest
|
41
|
+
path = case options.template
|
42
|
+
when 'default' ; 'spec.html'
|
43
|
+
when 'rhino' ; 'spec.js'
|
44
|
+
else
|
45
|
+
end
|
46
|
+
if path
|
47
|
+
spec = File.join dest, 'spec', path
|
48
|
+
contents = File.read(spec).gsub 'JSPEC_ROOT', JSPEC_ROOT
|
49
|
+
File.open(spec, 'w') { |file| file.write contents }
|
50
|
+
end
|
51
|
+
say "Template initialized at '#{dest}'"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
command :update do |c|
|
56
|
+
c.syntax = 'jspec update [path ...]'
|
57
|
+
c.summary = 'Update JSpec releases'
|
58
|
+
c.description = 'Update JSpec release in [paths], this will allow you to utilize the latest
|
59
|
+
JSpec features. If you have suites running at a path other than the regular
|
60
|
+
spec/spec.html simply pass them as arguments to this sub-command.
|
61
|
+
|
62
|
+
This is only needed when using the default, or rhino project templates.'
|
63
|
+
c.when_called do |args, options|
|
64
|
+
args = %w( spec/spec.html ) if args.empty?
|
65
|
+
args.each do |path|
|
66
|
+
next unless File.exists? path
|
67
|
+
contents = File.read(path).gsub /visionmedia-jspec-(\d+\.\d+\.\d+)/, "visionmedia-jspec-#{program[:version]}"
|
68
|
+
File.open(path, 'r+'){ |file| file.write contents }
|
69
|
+
say "Updated #{path} to JSpec #{program[:version]}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
command :run do |c|
|
75
|
+
c.syntax = 'jspec run [path] [options]'
|
76
|
+
c.summary = 'Run specifications'
|
77
|
+
c.description = 'Run specifications, defaulting [path] to spec/spec.html. You will need
|
78
|
+
supply [path] if your specs do not reside in this location. `run --bind` is
|
79
|
+
the default sub-command of jspec so you may simply execute `jspec` in order
|
80
|
+
to bind execution of your specs when a file is altered.
|
81
|
+
|
82
|
+
JSpec supports Rhino execution when installed. The [path] is assumed to be
|
83
|
+
spec/spec.js unless specified. See examples below for using the --rhino switch.'
|
84
|
+
c.example 'Run once in Safari', 'jspec run'
|
85
|
+
c.example 'Run once in Safari and Firefox', 'jspec run --browsers Safari,Firefox'
|
86
|
+
c.example 'Run custom spec file', 'jspec run foo.html'
|
87
|
+
c.example 'Auto-run browsers when a file is altered', 'jspec run --bind --browsers Safari,Firefox'
|
88
|
+
c.example 'Shortcut for the previous example', 'jspec --browsers Safari,Firefox'
|
89
|
+
c.example 'Auto-run rhino when a file is altered', 'jspec --rhino'
|
90
|
+
c.example 'Run Rhino specs once', 'jspec run --rhino'
|
91
|
+
c.option '-b', '--browsers BROWSERS', Array, 'Specify browsers to test, defaults to Safari'
|
92
|
+
c.option '-p', '--paths PATHS', Array, 'Specify paths when binding, defaults to javascript within ./lib and ./spec'
|
93
|
+
c.option '-B', '--bind', 'Auto-run specs when source files or specs are altered'
|
94
|
+
c.option '-R', '--rhino', 'Run specs using Rhino'
|
95
|
+
c.option '-S', '--server', 'Run specs using the JSpec server'
|
96
|
+
c.option '-s', '--server-only', 'Start JSpec server without running browsers'
|
97
|
+
c.when_called do |args, options|
|
98
|
+
begin
|
99
|
+
require 'bind'
|
100
|
+
options.default :browsers => %w( Safari ), :paths => ['lib/**/*.js', 'spec/**/*.js']
|
101
|
+
|
102
|
+
# Actions
|
103
|
+
if options.rhino
|
104
|
+
spec = args.shift || 'spec/spec.js'
|
105
|
+
action = lambda { rhino spec }
|
106
|
+
elsif options.server
|
107
|
+
spec = args.shift || 'spec/spec.html'
|
108
|
+
action = lambda { start_server options, spec }
|
109
|
+
else
|
110
|
+
spec = args.shift || 'spec/spec.html'
|
111
|
+
action = Bind::Actions::RefreshBrowsers.new spec, *options.browsers
|
112
|
+
end
|
113
|
+
|
114
|
+
# Binding
|
115
|
+
if options.bind
|
116
|
+
listener = Bind::Listener.new :paths => options.paths, :interval => 1, :actions => [action], :debug => $stdout
|
117
|
+
listener.run!
|
118
|
+
else
|
119
|
+
action.call File.new(spec)
|
120
|
+
end
|
121
|
+
|
122
|
+
rescue LoadError
|
123
|
+
abort "jspec run requires the visionmedia-bind gem; http://visionmedia.github.com/bind/"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
alias_command :bind, :run, '--bind'
|
128
|
+
|
129
|
+
def rhino file
|
130
|
+
abort "#{file} not found" unless File.exists? file
|
131
|
+
system "#{RHINO} #{file}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def start_server options, spec
|
135
|
+
require 'server/server'
|
136
|
+
JSpec::Server.start options, spec
|
137
|
+
end
|
data/jspec.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{jspec}
|
5
|
+
s.version = "2.0.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["visionmedia raus22"]
|
9
|
+
s.date = %q{2009-06-03}
|
10
|
+
s.default_executable = %q{jspec}
|
11
|
+
s.description = %q{JavaScript BDD Testing Framework}
|
12
|
+
s.email = %q{tj@vision-media.ca}
|
13
|
+
s.executables = ["jspec"]
|
14
|
+
s.extra_rdoc_files = ["bin/jspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "README.rdoc"]
|
15
|
+
s.files = ["bin/jspec", "History.rdoc", "jspec.gemspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/jquery-1.3.1.js", "spec/server.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.html", "spec/spec.jquery.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.rhino.js", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/spec.core.js", "templates/default/spec/spec.html", "templates/rhino/History.rdoc", "templates/rhino/lib/yourlib.core.js", "templates/rhino/README.rdoc", "templates/rhino/spec/spec.core.js", "templates/rhino/spec/spec.js", "templates/server/History.rdoc", "templates/server/lib/yourlib.core.js", "templates/server/README.rdoc", "templates/server/spec/spec.core.js", "templates/server/spec/spec.html"]
|
16
|
+
s.homepage = %q{http://github.com/raus22/jspec/tree/master}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jspec", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{jspec}
|
20
|
+
s.rubygems_version = %q{1.3.3}
|
21
|
+
s.summary = %q{JavaScript BDD Testing Framework}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
|
34
|
+
end
|
35
|
+
end
|
data/lib/images/bg.png
ADDED
Binary file
|
data/lib/images/hr.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/images/vr.png
ADDED
Binary file
|
data/lib/jspec.css
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
body.jspec {
|
2
|
+
margin: 45px 0;
|
3
|
+
font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
4
|
+
background: #efefef url(images/bg.png) top left repeat-x;
|
5
|
+
}
|
6
|
+
#jspec {
|
7
|
+
margin: 0 auto;
|
8
|
+
padding-top: 25px;
|
9
|
+
width: 1008px;
|
10
|
+
background: url(images/vr.png) top left repeat-y;
|
11
|
+
text-align: left;
|
12
|
+
}
|
13
|
+
#jspec-top {
|
14
|
+
position: relative;
|
15
|
+
margin: 0 auto;
|
16
|
+
width: 1008px;
|
17
|
+
height: 40px;
|
18
|
+
background: url(images/sprites.bg.png) top left no-repeat;
|
19
|
+
}
|
20
|
+
#jspec-bottom {
|
21
|
+
margin: 0 auto;
|
22
|
+
width: 1008px;
|
23
|
+
height: 15px;
|
24
|
+
background: url(images/sprites.bg.png) bottom left no-repeat;
|
25
|
+
}
|
26
|
+
#jspec .loading {
|
27
|
+
margin-top: -45px;
|
28
|
+
width: 1008px;
|
29
|
+
height: 80px;
|
30
|
+
background: url(images/loading.gif) 50% 50% no-repeat;
|
31
|
+
}
|
32
|
+
#jspec-title {
|
33
|
+
position: relative;
|
34
|
+
top: 35px;
|
35
|
+
left: 20px;
|
36
|
+
width: 160px;
|
37
|
+
font-size: 22px;
|
38
|
+
font-weight: normal;
|
39
|
+
background: url(images/sprites.png) 0 -126px no-repeat;
|
40
|
+
text-align: center;
|
41
|
+
}
|
42
|
+
#jspec-title em {
|
43
|
+
font-size: 10px;
|
44
|
+
font-style: normal;
|
45
|
+
color: #BCC8D1;
|
46
|
+
}
|
47
|
+
#jspec-report * {
|
48
|
+
margin: 0;
|
49
|
+
padding: 0;
|
50
|
+
background: none;
|
51
|
+
border: none;
|
52
|
+
}
|
53
|
+
#jspec-report {
|
54
|
+
padding: 15px 40px;
|
55
|
+
font: 11px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
56
|
+
color: #7B8D9B;
|
57
|
+
}
|
58
|
+
#jspec-report.has-failures {
|
59
|
+
padding-bottom: 30px;
|
60
|
+
}
|
61
|
+
#jspec-report .hidden {
|
62
|
+
display: none;
|
63
|
+
}
|
64
|
+
#jspec-report .heading {
|
65
|
+
margin-bottom: 15px;
|
66
|
+
}
|
67
|
+
#jspec-report .heading span {
|
68
|
+
padding-right: 10px;
|
69
|
+
}
|
70
|
+
#jspec-report .heading .passes em {
|
71
|
+
color: #0ea0eb;
|
72
|
+
}
|
73
|
+
#jspec-report .heading .failures em {
|
74
|
+
color: #FA1616;
|
75
|
+
}
|
76
|
+
#jspec-report table {
|
77
|
+
width: 100%;
|
78
|
+
font-size: 11px;
|
79
|
+
border-collapse: collapse;
|
80
|
+
}
|
81
|
+
#jspec-report td {
|
82
|
+
padding: 8px;
|
83
|
+
text-indent: 30px;
|
84
|
+
color: #7B8D9B;
|
85
|
+
}
|
86
|
+
#jspec-report tr.body {
|
87
|
+
display: none;
|
88
|
+
}
|
89
|
+
#jspec-report tr.body pre {
|
90
|
+
margin: 0;
|
91
|
+
padding: 0 0 5px 25px;
|
92
|
+
}
|
93
|
+
#jspec-report tr:not(.body):hover + tr.body {
|
94
|
+
display: block;
|
95
|
+
}
|
96
|
+
#jspec-report tr td:first-child em {
|
97
|
+
font-style: normal;
|
98
|
+
font-weight: normal;
|
99
|
+
color: #7B8D9B;
|
100
|
+
}
|
101
|
+
#jspec-report tr:not(.description):hover {
|
102
|
+
text-shadow: 1px 1px 1px #fff;
|
103
|
+
background: #F2F5F7;
|
104
|
+
}
|
105
|
+
#jspec-report td + td {
|
106
|
+
padding-right: 0;
|
107
|
+
width: 15px;
|
108
|
+
}
|
109
|
+
#jspec-report td.pass {
|
110
|
+
background: url(images/sprites.png) 3px -7px no-repeat;
|
111
|
+
}
|
112
|
+
#jspec-report td.fail {
|
113
|
+
background: url(images/sprites.png) 3px -47px no-repeat;
|
114
|
+
font-weight: bold;
|
115
|
+
color: #FC0D0D;
|
116
|
+
}
|
117
|
+
#jspec-report td.requires-implementation {
|
118
|
+
background: url(images/sprites.png) 3px -87px no-repeat;
|
119
|
+
}
|
120
|
+
#jspec-report tr.description td {
|
121
|
+
margin-top: 25px;
|
122
|
+
padding-top: 25px;
|
123
|
+
font-size: 12px;
|
124
|
+
font-weight: bold;
|
125
|
+
text-indent: 0;
|
126
|
+
color: #1a1a1a;
|
127
|
+
}
|
128
|
+
#jspec-report tr.description:first-child td {
|
129
|
+
border-top: none;
|
130
|
+
}
|
131
|
+
#jspec-report .assertion {
|
132
|
+
display: block;
|
133
|
+
float: left;
|
134
|
+
margin: 0 0 0 1px;
|
135
|
+
padding: 0;
|
136
|
+
width: 1px;
|
137
|
+
height: 5px;
|
138
|
+
background: #7B8D9B;
|
139
|
+
}
|
140
|
+
#jspec-report .assertion.failed {
|
141
|
+
background: red;
|
142
|
+
}
|
143
|
+
.jspec-sandbox {
|
144
|
+
display: none;
|
145
|
+
}
|
data/lib/jspec.jquery.js
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
// JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
|
+
|
4
|
+
(function(){
|
5
|
+
|
6
|
+
// --- Dependencies
|
7
|
+
|
8
|
+
JSpec.requires('jQuery', 'when using jspec.jquery.js')
|
9
|
+
|
10
|
+
// --- Async Support
|
11
|
+
|
12
|
+
jQuery.ajaxSetup({ async : false })
|
13
|
+
|
14
|
+
// --- Helpers
|
15
|
+
|
16
|
+
JSpec.defaultContext.element = jQuery
|
17
|
+
JSpec.defaultContext.elements = jQuery
|
18
|
+
JSpec.defaultContext.sandbox = function() { return jQuery('<div class="sandbox"></div>') }
|
19
|
+
|
20
|
+
// --- Matchers
|
21
|
+
|
22
|
+
JSpec.addMatchers({
|
23
|
+
have_tag : "jQuery(expected, actual).length == 1",
|
24
|
+
have_one : "alias have_tag",
|
25
|
+
have_tags : "jQuery(expected, actual).length > 1",
|
26
|
+
have_many : "alias have_tags",
|
27
|
+
have_child : "jQuery(actual).children(expected).length == 1",
|
28
|
+
have_children : "jQuery(actual).children(expected).length > 1",
|
29
|
+
have_text : "jQuery(actual).text() == expected",
|
30
|
+
have_value : "jQuery(actual).val() == expected",
|
31
|
+
be_visible : "!jQuery(actual).is(':hidden')",
|
32
|
+
be_hidden : "jQuery(actual).is(':hidden')",
|
33
|
+
be_enabled : "!jQuery(actual).attr('disabled')",
|
34
|
+
have_class : "jQuery(actual).hasClass(expected)",
|
35
|
+
|
36
|
+
have_classes : function(actual) {
|
37
|
+
return !JSpec.any(JSpec.argumentsToArray(arguments, 1), function(arg){
|
38
|
+
return !JSpec.does(actual, 'have_class', arg)
|
39
|
+
})
|
40
|
+
},
|
41
|
+
|
42
|
+
have_attr : function(actual, attr, value) {
|
43
|
+
return value ? jQuery(actual).attr(attr) == value:
|
44
|
+
jQuery(actual).attr(attr)
|
45
|
+
}
|
46
|
+
})
|
47
|
+
|
48
|
+
// --- be_BOOLATTR
|
49
|
+
|
50
|
+
JSpec.each('disabled selected checked', function(attr){
|
51
|
+
JSpec.addMatcher('be_' + attr, "jQuery(actual).attr('" + attr + "')")
|
52
|
+
})
|
53
|
+
|
54
|
+
// --- have_ATTR
|
55
|
+
|
56
|
+
JSpec.each('type id title alt href src rel rev name target', function(attr){
|
57
|
+
JSpec.addMatcher('have_' + attr, function(actual, value) {
|
58
|
+
return JSpec.matchers.have_attr.match(actual, attr, value)
|
59
|
+
})
|
60
|
+
})
|
61
|
+
|
62
|
+
})()
|
63
|
+
|
64
|
+
|