jspec 2.11.13 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/History.md +714 -0
  2. data/Manifest +51 -36
  3. data/README.md +968 -0
  4. data/Rakefile +4 -53
  5. data/bin/jspec +93 -224
  6. data/jspec.gemspec +5 -5
  7. data/lib/images/sprites.png +0 -0
  8. data/lib/jspec.css +2 -2
  9. data/lib/jspec.growl.js +115 -0
  10. data/lib/jspec.jquery.js +1 -1
  11. data/lib/jspec.js +98 -101
  12. data/lib/jspec.shell.js +5 -2
  13. data/lib/jspec.timers.js +1 -1
  14. data/lib/jspec.xhr.js +12 -2
  15. data/spec/commands/example_command.rb +19 -0
  16. data/spec/dom.html +33 -0
  17. data/spec/node.js +32 -0
  18. data/spec/rhino.js +24 -0
  19. data/spec/ruby/bin/init_spec.rb +101 -0
  20. data/spec/ruby/bin/install_spec.rb +141 -0
  21. data/spec/ruby/bin/run_spec.rb +0 -0
  22. data/spec/ruby/bin/shell_spec.rb +13 -0
  23. data/spec/ruby/bin/spec_helper.rb +25 -0
  24. data/spec/ruby/bin/update_spec.rb +72 -0
  25. data/spec/server.html +29 -0
  26. data/spec/server.rb +1 -1
  27. data/spec/{env.js → support/env.js} +554 -664
  28. data/spec/support/jquery.js +4376 -0
  29. data/spec/{helpers.js → unit/helpers.js} +2 -0
  30. data/spec/{spec.fixtures.js → unit/spec.fixtures.js} +0 -1
  31. data/spec/{spec.grammar-less.js → unit/spec.grammar-less.js} +0 -0
  32. data/spec/{spec.grammar.js → unit/spec.grammar.js} +1 -11
  33. data/spec/{spec.jquery.js → unit/spec.jquery.js} +0 -17
  34. data/spec/{spec.jquery.xhr.js → unit/spec.jquery.xhr.js} +13 -2
  35. data/spec/unit/spec.js +187 -0
  36. data/spec/{spec.matchers.js → unit/spec.matchers.js} +141 -66
  37. data/spec/{spec.modules.js → unit/spec.modules.js} +0 -0
  38. data/spec/{spec.shared-behaviors.js → unit/spec.shared-behaviors.js} +0 -0
  39. data/spec/{spec.utils.js → unit/spec.utils.js} +123 -22
  40. data/spec/{spec.xhr.js → unit/spec.xhr.js} +11 -10
  41. data/{server → src}/browsers.rb +23 -0
  42. data/{server → src}/helpers.rb +2 -17
  43. data/src/installables.rb +229 -0
  44. data/src/project.rb +340 -0
  45. data/{server → src}/routes.rb +1 -1
  46. data/{server → src}/server.rb +0 -0
  47. data/support/js.jar +0 -0
  48. data/templates/default/History.md +5 -0
  49. data/templates/default/{README.rdoc → Readme.md} +3 -3
  50. data/templates/default/lib/{yourlib.core.js → yourlib.js} +0 -0
  51. data/templates/default/spec/commands/example_command.rb +19 -0
  52. data/templates/default/spec/{spec.dom.html → dom.html} +5 -3
  53. data/templates/default/spec/rhino.js +10 -0
  54. data/templates/default/spec/server.html +18 -0
  55. data/templates/default/spec/unit/spec.helper.js +0 -0
  56. data/templates/default/spec/{spec.core.js → unit/spec.js} +0 -0
  57. data/templates/rails/commands/example_commands.rb +19 -0
  58. data/templates/rails/{spec.dom.html → dom.html} +4 -2
  59. data/templates/rails/rhino.js +10 -0
  60. data/templates/rails/server.html +18 -0
  61. data/templates/rails/unit/spec.helper.js +0 -0
  62. data/templates/rails/{spec.application.js → unit/spec.js} +0 -0
  63. metadata +56 -41
  64. data/History.rdoc +0 -590
  65. data/README.rdoc +0 -842
  66. data/spec/async +0 -1
  67. data/spec/jquery.js +0 -19
  68. data/spec/spec.dom.html +0 -34
  69. data/spec/spec.js +0 -166
  70. data/spec/spec.node.js +0 -46
  71. data/spec/spec.rhino.js +0 -23
  72. data/spec/spec.server.html +0 -29
  73. data/templates/default/History.rdoc +0 -4
  74. data/templates/default/spec/spec.rhino.js +0 -8
  75. data/templates/default/spec/spec.server.html +0 -16
  76. data/templates/rails/spec.rhino.js +0 -8
  77. data/templates/rails/spec.server.html +0 -16
data/src/project.rb ADDED
@@ -0,0 +1,340 @@
1
+
2
+ module JSpec
3
+
4
+ #--
5
+ # Base project
6
+ #++
7
+
8
+ class Project
9
+
10
+ #--
11
+ # Constants
12
+ #++
13
+
14
+ BIND_PATHS = 'lib/**/*.js', 'spec/**/*.js'
15
+ RHINO = JSPEC_ROOT + '/support/js.jar'
16
+
17
+ ##
18
+ # Destination directory.
19
+
20
+ attr_reader :dest
21
+
22
+ ##
23
+ # Initialize project with _dest_.
24
+
25
+ def initialize dest
26
+ @dest = dest || '.'
27
+ end
28
+
29
+ ##
30
+ # Execute _file_ with Node.js
31
+
32
+ def node file
33
+ system "node #{file}"
34
+ end
35
+
36
+ ##
37
+ # Execute _file_ with Rhino.
38
+
39
+ def rhino file
40
+ system "java -jar #{rhino_jar} #{file}"
41
+ end
42
+
43
+ ##
44
+ # Locate Rhino jar.
45
+ #
46
+ # * checks spec/support/js.jar
47
+ # * defaults to JSpec's support/js.jar
48
+ #
49
+
50
+ def rhino_jar
51
+ if File.exists? normalize('support/js.jar')
52
+ normalize 'support/js.jar'
53
+ else
54
+ RHINO
55
+ end
56
+ end
57
+
58
+ ##
59
+ # Install project _name_ with _options_.
60
+
61
+ def install name, options = {}
62
+ raise ArgumentError, ':to option required' unless options.include? :to
63
+ project = JSpec::Installable.const_get(name.downcase.capitalize).new options
64
+ if project.use_progress_bar?
65
+ progress [:before, :install, :after],
66
+ :complete_message => project.install_message,
67
+ :format => "Installing #{name} (:progress_bar) %:percent_complete" do |method|
68
+ project.send method
69
+ end
70
+ else
71
+ project.before
72
+ project.install
73
+ project.after
74
+ say project.install_message
75
+ end
76
+ end
77
+
78
+ ##
79
+ # Initialize the project with _options_
80
+
81
+ def init! options = {}
82
+ verify_empty!
83
+ copy_template :default
84
+ vendorize_with_symlink if options.include? :symlink
85
+ vendorize_with_copy if options.include? :freeze
86
+ replace_root
87
+ end
88
+
89
+ ##
90
+ # Vendorize JSpec with symlink.
91
+
92
+ def vendorize_with_symlink
93
+ FileUtils.symlink "#{JSPEC_ROOT}/lib", normalize('lib'), :force => true
94
+ end
95
+
96
+ ##
97
+ # Vendorize JSpec with copy.
98
+
99
+ def vendorize_with_copy
100
+ FileUtils.cp_r "#{JSPEC_ROOT}/lib", normalize('lib')
101
+ end
102
+
103
+ ##
104
+ # Copy template _name_ to the destination.
105
+
106
+ def copy_template name, options = {}
107
+ FileUtils.mkdir_p dest
108
+ FileUtils.cp_r path_to_template(name), options[:to] ?
109
+ "#{dest}/#{options[:to]}" :
110
+ dest
111
+ end
112
+
113
+ ##
114
+ # Normalize _path_.
115
+
116
+ def normalize path
117
+ "#{dest}/spec/#{path}"
118
+ end
119
+
120
+ ##
121
+ # Check if we are working with vendorized JSpec.
122
+
123
+ def vendorized?
124
+ File.directory?(normalize(:lib)) && normalize(:lib)
125
+ end
126
+
127
+ ##
128
+ # Replace absolute JSPEC_ROOT paths.
129
+
130
+ def replace_root
131
+ replace_root_in 'dom.html', 'rhino.js', 'node.js'
132
+ end
133
+
134
+ ##
135
+ # Root JSpec directory.
136
+
137
+ def root
138
+ vendorized? ? './spec' : JSPEC_ROOT
139
+ end
140
+
141
+ ##
142
+ # Replace absolute JSPEC_ROOT _paths_.
143
+
144
+ def replace_root_in *paths
145
+ paths.each do |path|
146
+ jspec_root = root
147
+ jspec_root = '.' if vendorized? and path.include? '.html'
148
+ contents = File.read(normalize(path)).gsub 'JSPEC_ROOT', jspec_root
149
+ File.open(normalize(path), 'w') { |file| file.write contents }
150
+ end
151
+ end
152
+
153
+ ##
154
+ # Path to template _name_.
155
+
156
+ def path_to_template name
157
+ "#{JSPEC_ROOT}/templates/#{name}/."
158
+ end
159
+
160
+ ##
161
+ # Verify that the current directory is empty, otherwise
162
+ # prompt for continuation.
163
+
164
+ def verify_empty!
165
+ unless Dir[dest + '/*'].empty?
166
+ abort unless agree "`#{dest}' is not empty; continue? "
167
+ end
168
+ end
169
+
170
+ ##
171
+ # Update absolute paths and/or vendorized libraries.
172
+
173
+ def update!
174
+ if path = vendorized?
175
+ type = File.symlink?(path) ? :symlink : :copy
176
+ FileUtils.rm_rf normalize(:lib)
177
+ send "vendorize_with_#{type}"
178
+ say "updated #{type} #{path} -> #{program(:version)}"
179
+ else
180
+ ['dom.html', 'rhino.js', 'node.js'].each do |path|
181
+ path = normalize path
182
+ next unless File.exists? path
183
+ contents = File.read(path).gsub /jspec-(\d+\.\d+\.\d+)/, "jspec-#{program(:version)}"
184
+ if program(:version) == $1
185
+ say "skipping #{path}; already #{$1}"
186
+ next
187
+ end
188
+ File.open(path, 'r+'){ |file| file.write contents }
189
+ say "updated #{path}; #{$1} -> #{program(:version)}"
190
+ end
191
+ end
192
+ end
193
+
194
+ ##
195
+ # Start server with _path_ html and _options_.
196
+
197
+ def start_server path, options = {}
198
+ options[:port] ||= 4444
199
+ set :port, options[:port]
200
+ set :server, 'Mongrel'
201
+ enable :sessions
202
+ disable :logging
203
+ hook = File.expand_path normalize('server.rb')
204
+ load hook if File.exists? hook
205
+ browsers = browsers_for(options[:browsers]) if options.include? :browsers
206
+ JSpec::Server.new(path, options[:port]).start(browsers)
207
+ end
208
+
209
+ ##
210
+ # Return array of browser instances for the given _names_.
211
+
212
+ def browsers_for names
213
+ names.map do |name|
214
+ begin
215
+ Browser.subclasses.find do |browser|
216
+ browser.matches_name? name
217
+ end.new
218
+ rescue
219
+ raise "Unsupported browser `#{name}'"
220
+ end
221
+ end
222
+ end
223
+
224
+ ##
225
+ # Run _path_ with _options_.
226
+
227
+ def run! path = nil, options = {}
228
+ paths = options[:paths] || self.class::BIND_PATHS
229
+
230
+ # Action
231
+
232
+ case
233
+ when options.include?(:node)
234
+ path ||= normalize('node.js')
235
+ action = lambda { node(path) }
236
+ when options.include?(:rhino)
237
+ path ||= normalize('rhino.js')
238
+ action = lambda { rhino(path) }
239
+ when options.include?(:server)
240
+ raise 'Cannot use --bind with --server' if options.include? :bind
241
+ path ||= normalize('server.html')
242
+ action = lambda { start_server path, options }
243
+ else
244
+ path ||= normalize('dom.html')
245
+ browsers = browsers_for options[:browsers] || ['default']
246
+ action = lambda do
247
+ browsers.each do |browser|
248
+ browser.visit File.expand_path(path)
249
+ end
250
+ end
251
+ end
252
+
253
+ # Bind action
254
+
255
+ if options.include? :bind
256
+ Bind::Listener.new(
257
+ :paths => paths,
258
+ :interval => 1,
259
+ :actions => [action],
260
+ :debug => $stdout).run!
261
+ else
262
+ exit !! action.call
263
+ end
264
+ end
265
+
266
+ ##
267
+ # Return the Project instance which should be used for _dest_.
268
+
269
+ def self.for dest
270
+ (File.directory?("#{dest}/vendor") ?
271
+ JSpec::Project::Rails :
272
+ JSpec::Project).new(dest)
273
+ end
274
+
275
+ ##
276
+ # Load all commands at the given _dir_.
277
+
278
+ def self.load_commands_at dir
279
+ Dir["#{dir}/**/*_command.rb"].each { |file| load file }
280
+ end
281
+
282
+ #--
283
+ # Rails project
284
+ #++
285
+
286
+ class Rails < self
287
+
288
+ #--
289
+ # Constants
290
+ #++
291
+
292
+ BIND_PATHS = 'public/javascripts/**/*.js', 'jspec/**/*.js'
293
+
294
+ ##
295
+ # Initialize the project with _options_
296
+
297
+ def init! options = {}
298
+ verify_rails!
299
+ copy_template :rails, :to => :jspec
300
+ vendorize_with_symlink if options.include? :symlink
301
+ vendorize_with_copy if options.include? :freeze
302
+ replace_root
303
+ end
304
+
305
+ ##
306
+ # Root JSpec directory.
307
+
308
+ def root
309
+ vendorized? ? './jspec' : JSPEC_ROOT
310
+ end
311
+
312
+ ##
313
+ # Normalize _path_.
314
+
315
+ def normalize path
316
+ "#{dest}/jspec/#{path}"
317
+ end
318
+
319
+ ##
320
+ # Verify that the current directory is rails, otherwise
321
+ # prompt for continuation.
322
+
323
+ def verify_rails!
324
+ unless rails?
325
+ abort unless agree "`#{dest}' does not appear to be a rails app; continue? "
326
+ end
327
+ end
328
+
329
+ ##
330
+ # Check if the destination is the root of
331
+ # a rails application.
332
+
333
+ def rails?
334
+ File.directory? dest + '/vendor'
335
+ end
336
+
337
+ end
338
+
339
+ end
340
+ end
@@ -39,7 +39,7 @@ post '/results' do
39
39
  end
40
40
 
41
41
  get '/*' do |path|
42
- pass unless File.exists?(path)
42
+ pass unless File.exists? path
43
43
  send_file path
44
44
  end
45
45
 
File without changes
data/support/js.jar ADDED
Binary file
@@ -0,0 +1,5 @@
1
+
2
+ 0.0.1 / YYYY-MM-DD
3
+ ------------------
4
+
5
+ * Initial release
@@ -1,13 +1,13 @@
1
1
 
2
- = YourLib
2
+ # YourLib
3
3
 
4
4
  Description
5
5
 
6
- == License
6
+ ## License
7
7
 
8
8
  (The MIT License)
9
9
 
10
- Copyright (c) 2009 Your Name <Your Email>
10
+ Copyright (c) 2009 Your Name &lt;Your Email&gt;
11
11
 
12
12
  Permission is hereby granted, free of charge, to any person obtaining
13
13
  a copy of this software and associated documentation files (the
@@ -0,0 +1,19 @@
1
+
2
+ # uncomment and call with `$ jspec example `
3
+
4
+ # command :example do |c|
5
+ # c.syntax = 'jspec example [options]'
6
+ # c.description = 'Just an example command'
7
+ # c.option '-f', '--foo string', 'Does some foo with <string>'
8
+ # c.option '-b', '--bar [string]', 'Does some bar with [string]'
9
+ # c.example 'Do some foo', 'jspec example --foo bar'
10
+ # c.example 'Do some bar', 'jspec example --bar'
11
+ # c.when_called do |args, options|
12
+ # p args
13
+ # p options.__hash__
14
+ # # options.foo
15
+ # # options.bar
16
+ # # options.__hash__[:foo]
17
+ # # options.__hash__[:bar]
18
+ # end
19
+ # end
@@ -2,13 +2,15 @@
2
2
  <head>
3
3
  <link type="text/css" rel="stylesheet" href="JSPEC_ROOT/lib/jspec.css" />
4
4
  <script src="JSPEC_ROOT/lib/jspec.js"></script>
5
- <script src="../lib/yourlib.core.js"></script>
5
+ <script src="JSPEC_ROOT/lib/jspec.xhr.js"></script>
6
+ <script src="../lib/yourlib.js"></script>
7
+ <script src="unit/spec.helper.js"></script>
6
8
  <script>
7
9
  function runSuites() {
8
10
  JSpec
9
- .exec('spec.core.js')
11
+ .exec('unit/spec.js')
10
12
  .run()
11
- .report()
13
+ .report({ fixturePath: 'fixtures' })
12
14
  }
13
15
  </script>
14
16
  </head>
@@ -0,0 +1,10 @@
1
+
2
+ load('JSPEC_ROOT/lib/jspec.js')
3
+ load('JSPEC_ROOT/lib/jspec.xhr.js')
4
+ load('lib/yourlib.js')
5
+ load('spec/unit/spec.helper.js')
6
+
7
+ JSpec
8
+ .exec('spec/unit/spec.js')
9
+ .run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures' })
10
+ .report()
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <script src="/jspec/jspec.js"></script>
4
+ <script src="/jspec/jspec.xhr.js"></script>
5
+ <script src="/lib/yourlib.js"></script>
6
+ <script src="/spec/unit/spec.helper.js"></script>
7
+ <script>
8
+ function runSuites() {
9
+ JSpec
10
+ .exec('unit/spec.js')
11
+ .run({ reporter: JSpec.reporters.Server, verbose: true, failuresOnly: true, fixturePath: '/spec/fixtures' })
12
+ .report()
13
+ }
14
+ </script>
15
+ </head>
16
+ <body class="jspec" onLoad="runSuites();">
17
+ </body>
18
+ </html>