visionmedia-jspec 2.8.4 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.rdoc CHANGED
@@ -1,4 +1,25 @@
1
1
 
2
+ === 2.9.0 / 2009-08-21
3
+
4
+ * Server output matching Rhino when using verbose or failuresOnly options
5
+ * Added mock_request() and unmock_request() as aliases for mockRequest() and unmockRequest()
6
+ * Added JSpec.JSON.encode()
7
+ * Added default Sinatra routes /slow/NUMBER and /status/NUMBER for simulating
8
+ slow reponses and HTTP status codes.
9
+ * Added server support for loading spec/jspec.rb (or jspec/jspec.rb for rails)
10
+ Allowing additional browser support to be plugged in, as well as Sinatra routes.
11
+ * Added dependency for Sinatra (new server)
12
+ * Added a new Ruby server
13
+ * Added support for --bind and --server on various platforms
14
+ * Added Google Chrome support
15
+ * Added Internet Explorer support
16
+ * Change; --server without --browsers defaults to all supported browsers
17
+ * Removed JSpec.reportToServer()
18
+ Now utilizes JSpec.formatters.Server to handle this
19
+ functionality.
20
+ * Fixed Server output escaping (removed html escaping from puts()) [#13]
21
+ * Fixed JSpec.load(); returns responseText when 2xx or 0 (for file://)
22
+
2
23
  === 2.8.4 / 2009-08-02
3
24
 
4
25
  * Fixed error thrown when a module has no utilities
data/Manifest CHANGED
@@ -15,6 +15,8 @@ Manifest
15
15
  Rakefile
16
16
  README.rdoc
17
17
  server/browsers.rb
18
+ server/helpers.rb
19
+ server/routes.rb
18
20
  server/server.rb
19
21
  spec/async
20
22
  spec/env.js
@@ -22,6 +24,7 @@ spec/fixtures/test.html
22
24
  spec/fixtures/test.json
23
25
  spec/fixtures/test.xml
24
26
  spec/modules.js
27
+ spec/server.rb
25
28
  spec/spec.dom.html
26
29
  spec/spec.fixtures.js
27
30
  spec/spec.grammar-less.js
@@ -40,10 +43,12 @@ spec/spec.xhr.js
40
43
  templates/default/History.rdoc
41
44
  templates/default/lib/yourlib.core.js
42
45
  templates/default/README.rdoc
46
+ templates/default/spec/server.rb
43
47
  templates/default/spec/spec.core.js
44
48
  templates/default/spec/spec.dom.html
45
49
  templates/default/spec/spec.rhino.js
46
50
  templates/default/spec/spec.server.html
51
+ templates/rails/server.rb
47
52
  templates/rails/spec.application.js
48
53
  templates/rails/spec.dom.html
49
54
  templates/rails/spec.rhino.js
data/README.rdoc CHANGED
@@ -125,9 +125,10 @@ JSpec.options hash, by passing string-based option values via the
125
125
  query string, or passing a hash to run(). For example
126
126
  JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
127
127
 
128
- * profile {bool} when enabled, uses console.time() in order to display performance information in your console log as specs are completed. (DOM, Console)
129
- * failuresOnly {bool} displays only failing specs, making them quick to discover and fix (DOM, Terminal)
130
- * reportToId {string} an element id to report to when using the DOM formatter (DOM)
128
+ * profile {bool} when enabled, uses console.time() in order to display performance information in your console log as specs are completed. (DOM, Console)
129
+ * failuresOnly {bool} displays only failing specs, making them quick to discover and fix (DOM, Terminal, Server)
130
+ * reportToId {string} an element id to report to when using the DOM formatter (DOM)
131
+ * verbose {bool} verbose server output, defaults to false (Server)
131
132
 
132
133
  == Matchers
133
134
 
@@ -242,9 +243,9 @@ on any object when using the JSpec grammar:
242
243
 
243
244
  * Core
244
245
 
245
- - an_instance_of used in conjunction with the 'receive' matcher
246
- - mockRequest mock a request (requires jspec.xhr.js)
247
- - unmockRequest unmock requests (requests jspec.xhr.js)
246
+ - an_instance_of used in conjunction with the 'receive' matcher
247
+ - mockRequest, mock_request mock a request (requires jspec.xhr.js)
248
+ - unmockRequest, unmock_request unmock requests (requests jspec.xhr.js)
248
249
 
249
250
  * jQuery
250
251
 
@@ -545,7 +546,6 @@ anything that has been done by a Module.
545
546
  - loading(file) : loading a file : returning 'stop' will prevent loading
546
547
  - executing(file) : executing a file : returning 'stop' will prevent execution
547
548
  - posting(data, url) : posting data to a url : returning 'stop' will prevent request
548
- - reportingToServer(url) : reporting to server url : returning 'stop' will prevent reporting to server
549
549
  - preprocessing(input) : before input string is preprocessed : return input string for next hook to preprocess
550
550
  - stubbing(object, method, result) : called when stubbing an object's method, and return value (result). : (no return value)
551
551
  - requiring(dependency, message) : requiring a dependency : (no return value)
@@ -631,13 +631,35 @@ back to the terminal. It is essentially the same as using the DOM formatter
631
631
  and auto-testing each browser, however results are centralized to the terminal,
632
632
  removing the need to manually view each browser's output.
633
633
 
634
- Initialize project with:
635
- $ jspec init myproject
634
+ When utilizing the server if a file named spec/jspec.rb (or jspec/jspec.rb for rails)
635
+ is present, then it will be loaded before the server is started. This allows you to
636
+ add Sinatra routes, support additional Browsers, etc.
636
637
 
637
- Run with:
638
+ Run with all supported browsers:
638
639
  $ jspec run --server
639
640
 
641
+ Run with specific browsers:
642
+ $ jspec run --browsers Safari,Firefox,Chrome,Explorer
643
+
644
+ Run with alternative browser names:
645
+ $ jspec run --browsers safari,ff,chrome,ie
646
+
647
+ Browsers supported in core:
648
+ Browser::Safari
649
+ Browser::Chrome
650
+ Browser::Opera
651
+ Browser::Firefox
652
+ Browser::IE
640
653
 
654
+ Supplied routes:
655
+ /slow/NUMBER
656
+ /status/NUMBER
657
+
658
+ For example $.get('/slow/4', function(){}) will take 4 seconds
659
+ to reply, where as $.get('/status/404', function(){}) will respond
660
+ with an 404 status code. Add additional Sinatra routes to the jspec.rb
661
+ file to add your own functionality.
662
+
641
663
  == Ruby on Rails
642
664
 
643
665
  No additional gems are required for JSpec to work with rails, although
@@ -677,6 +699,10 @@ Or run via the terminal using Rhino:
677
699
  return 'html'
678
700
  })
679
701
 
702
+ == Additional JSpec Modules
703
+
704
+ * JSocka stubbing http://github.com/gisikw/jsocka/tree/master
705
+
680
706
  == More Information
681
707
 
682
708
  * Featured article in JSMag: http://www.jsmag.com/main.issues.description/id=21/
data/Rakefile CHANGED
@@ -12,6 +12,8 @@ Echoe.new "jspec", version do |p|
12
12
  p.email = "tj@vision-media.ca"
13
13
  p.summary = "JavaScript BDD Testing Framework"
14
14
  p.url = "http://visionmedia.github.com/jspec"
15
+ p.runtime_dependencies << "sinatra"
16
+ p.runtime_dependencies << "json"
15
17
  p.runtime_dependencies << "visionmedia-commander >=3.2.9"
16
18
  p.runtime_dependencies << "visionmedia-bind >=0.2.6"
17
19
  end
data/bin/jspec CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  JSPEC_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
4
  $:.unshift JSPEC_ROOT
5
-
5
+
6
6
  require 'rubygems'
7
7
  require 'commander'
8
8
  require 'bind'
9
9
  require 'fileutils'
10
+ require 'server/server'
10
11
 
11
12
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
12
13
 
13
14
  program :name, 'JSpec'
14
- program :version, '2.8.4'
15
+ program :version, '2.9.0'
15
16
  program :description, 'JavaScript BDD Testing Framework'
16
17
  default_command :bind
17
18
 
@@ -26,9 +27,9 @@ command :init do |c|
26
27
  c.when_called do |args, options|
27
28
  dest = args.shift || '.'
28
29
  if options.rails
29
- initialize_rails_to dest
30
+ initialize_rails_at dest
30
31
  else
31
- initialize_to dest
32
+ initialize_at dest
32
33
  end
33
34
  say "Template initialized at '#{dest}'"
34
35
  end
@@ -71,38 +72,44 @@ command :run do |c|
71
72
  the [path] to spec/server.html'
72
73
  c.example 'Run once in Safari', 'jspec run'
73
74
  c.example 'Run once in Safari and Firefox', 'jspec run --browsers Safari,Firefox'
75
+ c.example 'Run once in Opera, Firefox, and Chrome', 'jspec run --browsers opera,ff,chrome'
74
76
  c.example 'Run custom spec file', 'jspec run foo.html'
75
77
  c.example 'Auto-run browsers when a file is altered', 'jspec run --bind --browsers Safari,Firefox'
76
78
  c.example 'Shortcut for the previous example', 'jspec --browsers Safari,Firefox'
77
79
  c.example 'Auto-run rhino when a file is altered', 'jspec --rhino'
80
+ c.example 'Run Rhino specs at spec/rhino.js', 'jspec run --rhino'
78
81
  c.example 'Run Rhino specs once', 'jspec run specs/something.js --rhino'
79
- c.option '-b', '--browsers BROWSERS', Array, 'Specify browsers to test, defaults to Safari'
82
+ c.option '-b', '--browsers BROWSERS', Array, 'Specify browsers to test'
80
83
  c.option '-p', '--paths PATHS', Array, 'Specify paths when binding, defaults to javascript within ./lib and ./spec'
81
84
  c.option '-B', '--bind', 'Auto-run specs when source files or specs are altered'
82
85
  c.option '-R', '--rhino', 'Run specs using Rhino'
83
86
  c.option '-S', '--server', 'Run specs using the JSpec server'
84
- c.option '-s', '--server-only', 'Start JSpec server without running browsers'
87
+ c.option '-P', '--port NUMBER', Integer, 'Start JSpec server using the given port number'
85
88
  c.when_called do |args, options|
86
89
 
87
90
  # Rails
88
91
  if rails?
89
- options.default :browsers => %w( Safari ), :paths => ['public/javascripts/**/*.js', 'jspec/**/*.js']
90
- else
91
- options.default :browsers => %w( Safari ), :paths => ['lib/**/*.js', 'spec/**/*.js']
92
+ options.default :paths => ['public/javascripts/**/*.js', 'jspec/**/*.js'], :port => 4444
93
+ else
94
+ options.default :paths => ['lib/**/*.js', 'spec/**/*.js'], :port => 4444
92
95
  end
93
96
 
94
97
  # Actions
95
98
  if options.rhino
96
- spec = args.shift || path_to('spec.rhino.js')
97
- action = lambda { rhino spec }
98
- elsif options.server_only
99
- start_server options, nil
99
+ suite = args.shift || path_to('spec.rhino.js')
100
+ action = lambda { rhino suite }
100
101
  elsif options.server
101
- spec = args.shift || path_to('spec.server.html')
102
- action = lambda { start_server options, spec }
102
+ raise 'Cannot use --server with --bind' if options.bind
103
+ suite = args.shift || path_to('spec.server.html')
104
+ action = lambda { start_server suite, options }
103
105
  else
104
- spec = args.shift || path_to('spec.dom.html')
105
- action = Bind::Actions::RefreshBrowsers.new spec, *options.browsers
106
+ suite = args.shift || path_to('spec.dom.html')
107
+ browsers = browsers_for options.browsers || ['safari']
108
+ action = lambda do
109
+ browsers.each do |browser|
110
+ browser.visit File.expand_path(suite)
111
+ end
112
+ end
106
113
  end
107
114
 
108
115
  # Binding
@@ -110,13 +117,16 @@ command :run do |c|
110
117
  listener = Bind::Listener.new :paths => options.paths, :interval => 1, :actions => [action], :debug => $stdout
111
118
  listener.run!
112
119
  else
113
- action.call File.new(spec)
120
+ action.call File.new(suite)
114
121
  end
115
122
  end
116
123
  end
117
124
  alias_command :bind, :run, '--bind'
118
125
 
119
- def initialize_to dest
126
+ ##
127
+ # Initialize template at _dest_.
128
+
129
+ def initialize_at dest
120
130
  unless Dir[dest + '/*'].empty?
121
131
  abort unless agree "'#{dest}' is not empty; continue? "
122
132
  end
@@ -124,7 +134,10 @@ def initialize_to dest
124
134
  replace_root_in dest, 'spec/spec.dom.html', 'spec/spec.rhino.js'
125
135
  end
126
136
 
127
- def initialize_rails_to dest
137
+ ##
138
+ # Initialize rails template at _dest_.
139
+
140
+ def initialize_rails_at dest
128
141
  unless looks_like_rails_root?(dest)
129
142
  abort unless agree "'#{dest}' does not look like root of a rails project; continue? "
130
143
  end
@@ -132,33 +145,74 @@ def initialize_rails_to dest
132
145
  replace_root_in "#{dest}/jspec", 'spec.dom.html', 'spec.rhino.js'
133
146
  end
134
147
 
148
+ ##
149
+ # Copy template _name_ to _dest_.
150
+
135
151
  def copy_template_to name, dest
136
152
  FileUtils.mkdir_p dest
137
153
  FileUtils.cp_r path_to_template(name), dest
138
154
  end
139
155
 
156
+ ##
157
+ # Return path to template _name_.
158
+
140
159
  def path_to_template name
141
160
  File.join JSPEC_ROOT, 'templates', name, '.'
142
161
  end
143
162
 
163
+ ##
164
+ # Resolve path to _file_. Supports rails and unbound projects.
165
+
144
166
  def path_to file
145
167
  rails? ? "jspec/#{file}" : "spec/#{file}"
146
168
  end
147
169
 
170
+ ##
171
+ # Execute _file_ with Rhino.
172
+
148
173
  def rhino file
149
- abort "#{file} not found" unless File.exists? file
174
+ raise "#{file} not found" unless File.exists? file
150
175
  system "#{RHINO} #{file}"
151
176
  end
152
177
 
153
- def start_server options, spec
154
- require 'server/server'
155
- JSpec::Server.start options, spec
178
+ ##
179
+ # Start server with _suite_ html and _options_.
180
+
181
+ def start_server suite, options
182
+ set :port, options.port
183
+ set :server, 'Mongrel'
184
+ enable :sessions
185
+ disable :logging
186
+ hook = File.expand_path path_to('server.rb')
187
+ load hook if File.exists? hook
188
+ JSpec::Server.new(suite, options.port).start(options.browsers ? browsers_for(options.browsers) : nil)
156
189
  end
157
190
 
191
+ ##
192
+ # Return array of browser instances for the given _names_.
193
+
194
+ def browsers_for names
195
+ names.map do |name|
196
+ begin
197
+ Browser.subclasses.find do |browser|
198
+ browser.matches_name? name
199
+ end.new
200
+ rescue
201
+ raise "Unsupported browser `#{name}'"
202
+ end
203
+ end
204
+ end
205
+
206
+ ##
207
+ # Check if the current directory looks like a rails app.
208
+
158
209
  def rails?
159
210
  File.directory? 'jspec'
160
211
  end
161
212
 
213
+ ##
214
+ # Replace JSPEC_ROOT placeholder in _paths_ relative to _dest_.
215
+
162
216
  def replace_root_in dest, *paths
163
217
  paths.each do |path|
164
218
  path = File.join dest, path
@@ -167,6 +221,9 @@ def replace_root_in dest, *paths
167
221
  end
168
222
  end
169
223
 
224
+ ##
225
+ # Update JSpec version in _paths_. Matches visionmedia-jspec-TRIPLE
226
+
170
227
  def update_version_in *paths
171
228
  paths.each do |path|
172
229
  next unless File.exists? path
@@ -177,6 +234,9 @@ def update_version_in *paths
177
234
  say "Finished updating JSpec"
178
235
  end
179
236
 
237
+ ##
238
+ # Check if _path_ looks like a rails root directory.
239
+
180
240
  def looks_like_rails_root? path = '.'
181
241
  File.directory? "#{path}/vendor"
182
242
  end
data/jspec.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "2.8.4"
5
+ s.version = "2.9.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-08-02}
9
+ s.date = %q{2009-08-21}
10
10
  s.default_executable = %q{jspec}
11
11
  s.description = %q{JavaScript BDD Testing Framework}
12
12
  s.email = %q{tj@vision-media.ca}
13
13
  s.executables = ["jspec"]
14
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", "lib/jspec.xhr.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", "lib/jspec.xhr.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/fixtures/test.html", "spec/fixtures/test.json", "spec/fixtures/test.xml", "spec/modules.js", "spec/spec.dom.html", "spec/spec.fixtures.js", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.jquery.xhr.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.modules.js", "spec/spec.node.js", "spec/spec.rhino.js", "spec/spec.server.html", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "spec/spec.xhr.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.dom.html", "templates/default/spec/spec.rhino.js", "templates/default/spec/spec.server.html", "templates/rails/spec.application.js", "templates/rails/spec.dom.html", "templates/rails/spec.rhino.js", "templates/rails/spec.server.html"]
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", "lib/jspec.xhr.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/helpers.rb", "server/routes.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/fixtures/test.html", "spec/fixtures/test.json", "spec/fixtures/test.xml", "spec/modules.js", "spec/server.rb", "spec/spec.dom.html", "spec/spec.fixtures.js", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.jquery.xhr.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.modules.js", "spec/spec.node.js", "spec/spec.rhino.js", "spec/spec.server.html", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "spec/spec.xhr.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/server.rb", "templates/default/spec/spec.core.js", "templates/default/spec/spec.dom.html", "templates/default/spec/spec.rhino.js", "templates/default/spec/spec.server.html", "templates/rails/server.rb", "templates/rails/spec.application.js", "templates/rails/spec.dom.html", "templates/rails/spec.rhino.js", "templates/rails/spec.server.html"]
16
16
  s.homepage = %q{http://visionmedia.github.com/jspec}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jspec", "--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
@@ -25,13 +25,19 @@ Gem::Specification.new do |s|
25
25
  s.specification_version = 3
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
29
+ s.add_runtime_dependency(%q<json>, [">= 0"])
28
30
  s.add_runtime_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
29
31
  s.add_runtime_dependency(%q<visionmedia-bind>, [">= 0.2.6"])
30
32
  else
33
+ s.add_dependency(%q<sinatra>, [">= 0"])
34
+ s.add_dependency(%q<json>, [">= 0"])
31
35
  s.add_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
32
36
  s.add_dependency(%q<visionmedia-bind>, [">= 0.2.6"])
33
37
  end
34
38
  else
39
+ s.add_dependency(%q<sinatra>, [">= 0"])
40
+ s.add_dependency(%q<json>, [">= 0"])
35
41
  s.add_dependency(%q<visionmedia-commander>, [">= 3.2.9"])
36
42
  s.add_dependency(%q<visionmedia-bind>, [">= 0.2.6"])
37
43
  end
data/lib/jspec.jquery.js CHANGED
@@ -8,14 +8,14 @@ JSpec
8
8
  // --- Initialize
9
9
 
10
10
  init : function() {
11
- jQuery.ajaxSetup({ async : false })
11
+ jQuery.ajaxSetup({ async: false })
12
12
  },
13
13
 
14
14
  // --- Utilities
15
15
 
16
16
  utilities : {
17
- element : jQuery,
18
- elements : jQuery,
17
+ element: jQuery,
18
+ elements: jQuery,
19
19
  sandbox : function() {
20
20
  return jQuery('<div class="sandbox"></div>')
21
21
  }