visionmedia-jspec 2.5.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ === 2.6.0 / 2009-07-09
3
+
4
+ * Added Ruby on Rails support
5
+ * Added exporting of JSpec (node.js etc)
6
+ * Added be_undefined matcher [#134]
7
+
2
8
  === 2.5.1 / 2009-07-07
3
9
 
4
10
  * Added intermediate node.js support
data/Manifest CHANGED
@@ -38,3 +38,7 @@ templates/default/spec/spec.core.js
38
38
  templates/default/spec/spec.dom.html
39
39
  templates/default/spec/spec.rhino.js
40
40
  templates/default/spec/spec.server.html
41
+ templates/rails/spec.application.js
42
+ templates/rails/spec.dom.html
43
+ templates/rails/spec.rhino.js
44
+ templates/rails/spec.server.html
data/README.rdoc CHANGED
@@ -31,7 +31,7 @@ and much more.
31
31
  * Method Stubbing
32
32
  * Shared behaviors
33
33
  * Profiling
34
- * Rails Integration (http://github.com/bhauman/jspec-rails)
34
+ * Ruby on Rails Integration
35
35
  * Tiny (15 kb compressed, 1300-ish LOC)
36
36
 
37
37
  == Installation
@@ -143,6 +143,7 @@ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
143
143
  - be_type be type of x
144
144
  - be_greater_than >
145
145
  - be_less_than <
146
+ - be_undefined check if variable passed is undefined
146
147
  - throw_error should throw an error, optionally supply the error string or regexp for message comparison
147
148
  - have object should have n of property (person.should.have(2, 'pets'))
148
149
  - have_at_least object should have at least n of property
@@ -559,6 +560,29 @@ Initialize project with:
559
560
  Run with:
560
561
  $ jspec run --server
561
562
 
563
+
564
+ == Ruby on Rails
565
+
566
+ No additional gems are required for JSpec to work with rails, although
567
+ http://github.com/bhauman/jspec-rails has been created by 'bhauman'. JSpec
568
+ supports Rails out of the box, simply execute:
569
+
570
+ $ jspec init --rails
571
+
572
+ Then while still in the root directory of your Rails project, run the following
573
+ command which will bind to, and refresh your browsers automatically when any changes
574
+ are made to ./public/javascripts/*.js or ./jspec/*.js
575
+
576
+ $ jspec
577
+
578
+ Or just like regular JSpec applications, run once:
579
+
580
+ $ jspec run
581
+
582
+ Or run via the terminal using Rhino:
583
+
584
+ $ jspec run --rhino
585
+
562
586
  == Known Issues
563
587
 
564
588
  * Tabs may cause a parse error. To prevent this use 'soft tabs' (setting in your IDE/Editor)
data/bin/jspec CHANGED
@@ -11,7 +11,7 @@ require 'fileutils'
11
11
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
12
12
 
13
13
  program :name, 'JSpec'
14
- program :version, '2.5.1'
14
+ program :version, '2.6.0'
15
15
  program :description, 'JavaScript BDD Testing Framework'
16
16
  default_command :bind
17
17
 
@@ -22,18 +22,13 @@ command :init do |c|
22
22
  when [dest] is not specified. The template includes several files for
23
23
  running via Rhino, DOM, and the JSpec Rack server.'
24
24
  c.example 'Create a directory foo, initialized with a jspec template', 'jspec init foo'
25
+ c.option '-R', '--rails', 'Initialize rails template'
25
26
  c.when_called do |args, options|
26
27
  dest = args.shift || '.'
27
- unless Dir[dest + '/*'].empty?
28
- abort unless agree "'#{dest}' is not empty; continue? "
29
- end
30
- template = File.join JSPEC_ROOT, 'templates', 'default', '.'
31
- FileUtils.mkdir_p dest
32
- FileUtils.cp_r template, dest
33
- %w( spec/spec.dom.html spec/spec.rhino.js ).each do |path|
34
- path = File.join dest, path
35
- contents = File.read(path).gsub 'JSPEC_ROOT', JSPEC_ROOT
36
- File.open(path, 'w') { |file| file.write contents }
28
+ if options.rails
29
+ initialize_rails_to dest
30
+ else
31
+ initialize_to dest
37
32
  end
38
33
  say "Template initialized at '#{dest}'"
39
34
  end
@@ -46,13 +41,16 @@ command :update do |c|
46
41
  the latest JSpec features. Execute from JSpec project root without [paths] to
47
42
  update the default template spec files.'
48
43
  c.when_called do |args, options|
49
- paths = args.empty? ? %w( spec/spec.dom.html spec/spec.rhino.js ) : args
50
- paths.each do |path|
51
- next unless File.exists? path
52
- contents = File.read(path).gsub /visionmedia-jspec-(\d+\.\d+\.\d+)/, "visionmedia-jspec-#{program(:version)}"
53
- File.open(path, 'r+'){ |file| file.write contents }
54
- say "Updated #{path} to JSpec #{program(:version)}"
44
+ if args.empty?
45
+ if rails?
46
+ paths = 'jspec/spec.dom.html', 'jspec/spec.rhino.js'
47
+ else
48
+ paths = 'spec/spec.dom.html', 'spec/spec.rhino.js'
49
+ end
50
+ else
51
+ paths = args
55
52
  end
53
+ update_version_in *paths
56
54
  end
57
55
  end
58
56
 
@@ -85,17 +83,23 @@ command :run do |c|
85
83
  c.option '-S', '--server', 'Run specs using the JSpec server'
86
84
  c.option '-s', '--server-only', 'Start JSpec server without running browsers'
87
85
  c.when_called do |args, options|
88
- options.default :browsers => %w( Safari ), :paths => ['lib/**/*.js', 'spec/**/*.js']
86
+
87
+ # Rails
88
+ 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
+ end
89
93
 
90
94
  # Actions
91
95
  if options.rhino
92
- spec = args.shift || 'spec/spec.rhino.js'
96
+ spec = args.shift || path_to('spec.rhino.js')
93
97
  action = lambda { rhino spec }
94
98
  elsif options.server
95
- spec = args.shift || 'spec/spec.server.html'
99
+ spec = args.shift || path_to('spec.server.html')
96
100
  action = lambda { start_server options, spec }
97
101
  else
98
- spec = args.shift || 'spec/spec.dom.html'
102
+ spec = args.shift || path_to('spec.dom.html')
99
103
  action = Bind::Actions::RefreshBrowsers.new spec, *options.browsers
100
104
  end
101
105
 
@@ -110,6 +114,35 @@ command :run do |c|
110
114
  end
111
115
  alias_command :bind, :run, '--bind'
112
116
 
117
+ def initialize_to dest
118
+ unless Dir[dest + '/*'].empty?
119
+ abort unless agree "'#{dest}' is not empty; continue? "
120
+ end
121
+ copy_template_to 'default', dest
122
+ replace_root_in dest, 'spec/spec.dom.html', 'spec/spec.rhino.js'
123
+ end
124
+
125
+ def initialize_rails_to dest
126
+ unless looks_like_rails_root?(dest)
127
+ abort unless agree "'#{dest}' does not look like root of a rails project; continue? "
128
+ end
129
+ copy_template_to 'rails', "#{dest}/jspec"
130
+ replace_root_in "#{dest}/jspec", 'spec.dom.html', 'spec.rhino.js'
131
+ end
132
+
133
+ def copy_template_to name, dest
134
+ FileUtils.mkdir_p dest
135
+ FileUtils.cp_r path_to_template(name), dest
136
+ end
137
+
138
+ def path_to_template name
139
+ File.join JSPEC_ROOT, 'templates', name, '.'
140
+ end
141
+
142
+ def path_to file
143
+ rails? ? "jspec/#{file}" : "spec/#{file}"
144
+ end
145
+
113
146
  def rhino file
114
147
  abort "#{file} not found" unless File.exists? file
115
148
  system "#{RHINO} #{file}"
@@ -118,4 +151,30 @@ end
118
151
  def start_server options, spec
119
152
  require 'server/server'
120
153
  JSpec::Server.start options, spec
121
- end
154
+ end
155
+
156
+ def rails?
157
+ File.directory? 'jspec'
158
+ end
159
+
160
+ def replace_root_in dest, *paths
161
+ paths.each do |path|
162
+ path = File.join dest, path
163
+ contents = File.read(path).gsub 'JSPEC_ROOT', JSPEC_ROOT
164
+ File.open(path, 'w') { |file| file.write contents }
165
+ end
166
+ end
167
+
168
+ def update_version_in *paths
169
+ paths.each do |path|
170
+ next unless File.exists? path
171
+ contents = File.read(path).gsub /visionmedia-jspec-(\d+\.\d+\.\d+)/, "visionmedia-jspec-#{program(:version)}"
172
+ File.open(path, 'r+'){ |file| file.write contents }
173
+ say "Updated #{path}; #{$1} -> #{program(:version)}"
174
+ end
175
+ say "Finished updating JSpec"
176
+ end
177
+
178
+ def looks_like_rails_root? path = '.'
179
+ File.directory? "#{path}/vendor"
180
+ 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.5.1"
5
+ s.version = "2.6.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-07-07}
9
+ s.date = %q{2009-07-09}
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", "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/env.js", "spec/jquery-1.3.1.js", "spec/modules.js", "spec/spec.dom.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.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", "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"]
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/env.js", "spec/jquery-1.3.1.js", "spec/modules.js", "spec/spec.dom.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.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", "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"]
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"]
data/lib/jspec.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  JSpec = {
7
7
 
8
- version : '2.5.1',
8
+ version : '2.6.0',
9
9
  suites : [],
10
10
  modules : [],
11
11
  allSuites : [],
@@ -1511,6 +1511,7 @@
1511
1511
  be_null : "actual == null",
1512
1512
  be_true : "actual == true",
1513
1513
  be_false : "actual == false",
1514
+ be_undefined : "typeof actual == 'undefined'",
1514
1515
  be_type : "typeof actual == expected",
1515
1516
  match : "typeof actual == 'string' ? actual.match(expected) : false",
1516
1517
  respond_to : "typeof actual[expected] == 'function'",
@@ -1623,5 +1624,7 @@
1623
1624
  value === actual[property]
1624
1625
  }
1625
1626
  })
1627
+
1628
+ if ('exports' in main) exports.JSpec = JSpec
1626
1629
 
1627
1630
  })()
@@ -82,6 +82,13 @@ describe 'Matchers'
82
82
  end
83
83
  end
84
84
 
85
+ describe 'be_undefined'
86
+ it 'should check if a var is defined'
87
+ var foo
88
+ foo.should.be_undefined
89
+ end
90
+ end
91
+
85
92
  describe 'have_length'
86
93
  it 'should compare the length of an object'
87
94
  'foo'.should.have_length 3
@@ -0,0 +1,8 @@
1
+
2
+ describe 'YourLib'
3
+ describe '.someMethod()'
4
+ it 'should do something'
5
+ true.should.be true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <link type="text/css" rel="stylesheet" href="JSPEC_ROOT/lib/jspec.css" />
4
+ <script src="JSPEC_ROOT/lib/jspec.js"></script>
5
+ <script src="../public/javascripts/application.js"></script>
6
+ <script>
7
+ function runSuites() {
8
+ JSpec
9
+ .exec('spec.application.js')
10
+ .run()
11
+ .report()
12
+ }
13
+ </script>
14
+ </head>
15
+ <body class="jspec" onLoad="runSuites();">
16
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
17
+ <div id="jspec"></div>
18
+ <div id="jspec-bottom"></div>
19
+ </body>
20
+ </html>
@@ -0,0 +1,7 @@
1
+
2
+ load('JSPEC_ROOT/lib/jspec.js')
3
+
4
+ JSpec
5
+ .exec('spec/spec.application.js')
6
+ .run({ formatter : JSpec.formatters.Terminal })
7
+ .report()
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <script src="jspec.js"></script>
4
+ <script>
5
+ function runSuites() {
6
+ JSpec
7
+ .exec('spec.application.js')
8
+ .run()
9
+ .reportToServer()
10
+ }
11
+ </script>
12
+ </head>
13
+ <body class="jspec" onLoad="runSuites();">
14
+ </body>
15
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-jspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-07 00:00:00 -07:00
12
+ date: 2009-07-09 00:00:00 -07:00
13
13
  default_executable: jspec
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,10 @@ files:
91
91
  - templates/default/spec/spec.dom.html
92
92
  - templates/default/spec/spec.rhino.js
93
93
  - templates/default/spec/spec.server.html
94
+ - templates/rails/spec.application.js
95
+ - templates/rails/spec.dom.html
96
+ - templates/rails/spec.rhino.js
97
+ - templates/rails/spec.server.html
94
98
  has_rdoc: false
95
99
  homepage: http://visionmedia.github.com/jspec
96
100
  post_install_message: