jspec 2.11.13 → 3.0.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.md +714 -0
- data/Manifest +51 -36
- data/README.md +968 -0
- data/Rakefile +4 -53
- data/bin/jspec +93 -224
- data/jspec.gemspec +5 -5
- data/lib/images/sprites.png +0 -0
- data/lib/jspec.css +2 -2
- data/lib/jspec.growl.js +115 -0
- data/lib/jspec.jquery.js +1 -1
- data/lib/jspec.js +98 -101
- data/lib/jspec.shell.js +5 -2
- data/lib/jspec.timers.js +1 -1
- data/lib/jspec.xhr.js +12 -2
- data/spec/commands/example_command.rb +19 -0
- data/spec/dom.html +33 -0
- data/spec/node.js +32 -0
- data/spec/rhino.js +24 -0
- data/spec/ruby/bin/init_spec.rb +101 -0
- data/spec/ruby/bin/install_spec.rb +141 -0
- data/spec/ruby/bin/run_spec.rb +0 -0
- data/spec/ruby/bin/shell_spec.rb +13 -0
- data/spec/ruby/bin/spec_helper.rb +25 -0
- data/spec/ruby/bin/update_spec.rb +72 -0
- data/spec/server.html +29 -0
- data/spec/server.rb +1 -1
- data/spec/{env.js → support/env.js} +554 -664
- data/spec/support/jquery.js +4376 -0
- data/spec/{helpers.js → unit/helpers.js} +2 -0
- data/spec/{spec.fixtures.js → unit/spec.fixtures.js} +0 -1
- data/spec/{spec.grammar-less.js → unit/spec.grammar-less.js} +0 -0
- data/spec/{spec.grammar.js → unit/spec.grammar.js} +1 -11
- data/spec/{spec.jquery.js → unit/spec.jquery.js} +0 -17
- data/spec/{spec.jquery.xhr.js → unit/spec.jquery.xhr.js} +13 -2
- data/spec/unit/spec.js +187 -0
- data/spec/{spec.matchers.js → unit/spec.matchers.js} +141 -66
- data/spec/{spec.modules.js → unit/spec.modules.js} +0 -0
- data/spec/{spec.shared-behaviors.js → unit/spec.shared-behaviors.js} +0 -0
- data/spec/{spec.utils.js → unit/spec.utils.js} +123 -22
- data/spec/{spec.xhr.js → unit/spec.xhr.js} +11 -10
- data/{server → src}/browsers.rb +23 -0
- data/{server → src}/helpers.rb +2 -17
- data/src/installables.rb +229 -0
- data/src/project.rb +340 -0
- data/{server → src}/routes.rb +1 -1
- data/{server → src}/server.rb +0 -0
- data/support/js.jar +0 -0
- data/templates/default/History.md +5 -0
- data/templates/default/{README.rdoc → Readme.md} +3 -3
- data/templates/default/lib/{yourlib.core.js → yourlib.js} +0 -0
- data/templates/default/spec/commands/example_command.rb +19 -0
- data/templates/default/spec/{spec.dom.html → dom.html} +5 -3
- data/templates/default/spec/rhino.js +10 -0
- data/templates/default/spec/server.html +18 -0
- data/templates/default/spec/unit/spec.helper.js +0 -0
- data/templates/default/spec/{spec.core.js → unit/spec.js} +0 -0
- data/templates/rails/commands/example_commands.rb +19 -0
- data/templates/rails/{spec.dom.html → dom.html} +4 -2
- data/templates/rails/rhino.js +10 -0
- data/templates/rails/server.html +18 -0
- data/templates/rails/unit/spec.helper.js +0 -0
- data/templates/rails/{spec.application.js → unit/spec.js} +0 -0
- metadata +56 -41
- data/History.rdoc +0 -590
- data/README.rdoc +0 -842
- data/spec/async +0 -1
- data/spec/jquery.js +0 -19
- data/spec/spec.dom.html +0 -34
- data/spec/spec.js +0 -166
- data/spec/spec.node.js +0 -46
- data/spec/spec.rhino.js +0 -23
- data/spec/spec.server.html +0 -29
- data/templates/default/History.rdoc +0 -4
- data/templates/default/spec/spec.rhino.js +0 -8
- data/templates/default/spec/spec.server.html +0 -16
- data/templates/rails/spec.rhino.js +0 -8
- data/templates/rails/spec.server.html +0 -16
data/Rakefile
CHANGED
@@ -18,58 +18,9 @@ Echoe.new "jspec", version do |p|
|
|
18
18
|
p.runtime_dependencies << "bind >=0.2.8"
|
19
19
|
end
|
20
20
|
|
21
|
-
namespace :
|
22
|
-
desc '
|
23
|
-
task :
|
24
|
-
|
25
|
-
sh 'mkdir pkg'
|
26
|
-
sh 'cp -fr lib/* pkg'
|
27
|
-
minify 'lib/jspec.js', 'pkg/jspec.min.js'
|
28
|
-
minify 'lib/jspec.jquery.js', 'pkg/jspec.jquery.min.js'
|
29
|
-
compress 'lib/jspec.css', 'pkg/jspec.min.css'
|
30
|
-
sh 'git add pkg/.'
|
31
|
-
rescue Exception => e
|
32
|
-
puts "Failed to package: #{e}."
|
33
|
-
else
|
34
|
-
puts "Packaging of JSpec-#{version} completed."
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
desc 'Clear packaging'
|
39
|
-
task :clear do
|
40
|
-
if File.directory? 'pkg'
|
41
|
-
sh 'rm -fr pkg/*'
|
42
|
-
sh 'rmdir pkg'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Display compression savings of last release'
|
47
|
-
task :savings do
|
48
|
-
totals = Hash.new { |h, k| h[k] = 0 }
|
49
|
-
format = '%-20s : %0.3f kb'
|
50
|
-
totals = %w( pkg/jspec.min.js pkg/jspec.jquery.min.js pkg/jspec.min.css ).inject totals do |total, file|
|
51
|
-
uncompressed = File.size(file.sub('.min', '')).to_f / 1024
|
52
|
-
compressed = File.size(file).to_f / 1024
|
53
|
-
saved = uncompressed - compressed
|
54
|
-
puts format % [file.sub('pkg/', ''), saved]
|
55
|
-
totals[:saved] += saved
|
56
|
-
totals[:uncompressed] += uncompressed
|
57
|
-
totals[:compressed] += compressed
|
58
|
-
totals
|
59
|
-
end
|
60
|
-
puts
|
61
|
-
puts format % ['total uncompressed', totals[:uncompressed]]
|
62
|
-
puts format % ['total compressed', totals[:compressed]]
|
63
|
-
puts format % ['total saved', totals[:saved]]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def minify from, to
|
68
|
-
sh "jsmin < #{from} > #{to}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def compress from, to
|
72
|
-
File.open(to, 'w+') do |file|
|
73
|
-
file.write File.read(from).gsub(/(^[\t ]*)|\n/, '')
|
21
|
+
namespace :spec do
|
22
|
+
desc 'Run jspec executable specs'
|
23
|
+
task :bin do
|
24
|
+
sh 'spec --color --require spec/ruby/bin/spec_helper.rb spec/ruby/bin/*_spec.rb'
|
74
25
|
end
|
75
26
|
end
|
data/bin/jspec
CHANGED
@@ -1,21 +1,77 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
JSPEC_ROOT = File.expand_path
|
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/import'
|
8
8
|
require 'bind'
|
9
9
|
require 'fileutils'
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
10
|
+
require 'src/project'
|
11
|
+
require 'src/installables'
|
12
|
+
require 'src/server'
|
13
13
|
|
14
14
|
program :name, 'JSpec'
|
15
|
-
program :version, '
|
15
|
+
program :version, '3.0.0'
|
16
16
|
program :description, 'JavaScript BDD Testing Framework'
|
17
17
|
default_command :bind
|
18
18
|
|
19
|
+
JSpec::Project.load_commands_at '~/.jspec/commands'
|
20
|
+
JSpec::Project.load_commands_at 'spec/commands'
|
21
|
+
JSpec::Project.load_commands_at 'jspec/commands'
|
22
|
+
|
23
|
+
command :stats do |c|
|
24
|
+
c.syntax = 'jspec stats [path ...]'
|
25
|
+
c.summary = 'View javascript source statistics'
|
26
|
+
c.description = 'View statistics for the given [paths], defaulting to /lib/**/*.js'
|
27
|
+
c.example 'View stats for all /lib javascript', 'jspec stats'
|
28
|
+
c.example 'View stats for all /public/javascript files', 'jspec stats public/javascript/*.js'
|
29
|
+
c.when_called do |paths, options|
|
30
|
+
paths = Dir['lib/**/*.js'] if paths.empty?
|
31
|
+
paths.each do |path|
|
32
|
+
contents = File.read path
|
33
|
+
say "%33s : \n" % $terminal.color(path, :bold)
|
34
|
+
say "%25s : %0.2f KiB\n" % ['size', File.size(path).to_f / 1024]
|
35
|
+
say "%25s : %d\n" % ['lines', contents.to_a.length]
|
36
|
+
say "%25s : %d\n" % ['comments', contents.scan(/\/\*.*?\*\/|\/\/.*?$/m).length]
|
37
|
+
say "%25s : %d\n" % ['functions', contents.scan(/function/i).length]
|
38
|
+
say "%25s : %d\n" % ['vars', contents.scan(/\bvar\b/).length]
|
39
|
+
say "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
command :install do |c|
|
45
|
+
c.syntax = 'jspec install <project> [dest]'
|
46
|
+
c.summary = 'Install a project such as jQuery, Prototype, Rhino, etc.'
|
47
|
+
c.description = 'Install the given <project> to [dest] or spec/support/<project>.
|
48
|
+
When --release is not specified, the latest stable release will be used.
|
49
|
+
Currently the following projects are supported:
|
50
|
+
|
51
|
+
- jquery
|
52
|
+
- jqueryui
|
53
|
+
- prototype
|
54
|
+
- mootools
|
55
|
+
- dojo
|
56
|
+
- envjs (--release not yet supported)
|
57
|
+
- rhino (--release not yet supported)'
|
58
|
+
c.option '-r', '--release STRING', 'Release version to install'
|
59
|
+
c.example 'Install jQuery to spec/support/jquery.js', 'jspec install jquery'
|
60
|
+
c.example 'Install jQuery 1.3.0 to spec/support/jquery.js', 'jspec install jquery --release 1.3.0'
|
61
|
+
c.example 'Install Prototype to spec/prototype.js', 'jspec install prototype spec'
|
62
|
+
c.example 'Install Prototype to spec/vendor/prototype.js', 'jspec install prototype spec/vendor'
|
63
|
+
c.when_called do |args, options|
|
64
|
+
name = args.shift or raise 'Project name required'
|
65
|
+
project = JSpec::Project.for '.'
|
66
|
+
if dest = args.shift
|
67
|
+
project.install name, :to => dest, :release => options.release
|
68
|
+
else
|
69
|
+
Dir.mkdir project.normalize('support') unless File.directory? project.normalize('support')
|
70
|
+
project.install name, :to => project.normalize('support'), :release => options.release
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
19
75
|
command :init do |c|
|
20
76
|
c.syntax = 'jspec init [dest]'
|
21
77
|
c.summary = 'Initialize a JSpec project template'
|
@@ -26,18 +82,20 @@ command :init do |c|
|
|
26
82
|
Additional switches --freeze, and --symlink are available in order
|
27
83
|
to preserve the version of JSpec at the time of initialization. Otherwise
|
28
84
|
incompatibilities from later versions may prevent your suite from
|
29
|
-
running properly.
|
85
|
+
running properly.
|
86
|
+
|
87
|
+
To update a project to the recent version of JSpec use
|
88
|
+
`jspec help udpate` for more information.'
|
30
89
|
c.option '-R', '--rails', 'Initialize rails template from rails root directory'
|
31
90
|
c.option '-f', '--freeze', 'Copy the JSpec library'
|
32
91
|
c.option '-s', '--symlink', 'Symlink the JSpec library instead of copying it'
|
92
|
+
c.example 'Create a project in the current directory', 'jspec init'
|
33
93
|
c.example 'Create a directory foo, initialized with a jspec template', 'jspec init foo'
|
94
|
+
c.example 'Rails application support', 'jspec init --rails'
|
95
|
+
c.example 'Rails application support, --rails is no longer required', 'jspec init'
|
96
|
+
c.example 'Freeze JSpec\'s library at spec/lib', 'jspec init --freeze'
|
34
97
|
c.when_called do |args, options|
|
35
|
-
dest = args.shift || '.'
|
36
|
-
if options.rails
|
37
|
-
initialize_rails_at dest, options
|
38
|
-
else
|
39
|
-
initialize_at dest, options
|
40
|
-
end
|
98
|
+
JSpec::Project.for(dest = args.shift || '.').init! options.__hash__
|
41
99
|
say "Template initialized at `#{dest}'"
|
42
100
|
end
|
43
101
|
end
|
@@ -45,7 +103,7 @@ end
|
|
45
103
|
command :shell do |c|
|
46
104
|
c.syntax = 'jspec shell [path ...]'
|
47
105
|
c.summary = 'JSpec interactive shell'
|
48
|
-
c.description = 'Launch interactive shell with jspec.js, jspec.shell.js,
|
106
|
+
c.description = 'Launch interactive Rhino shell with jspec.js, jspec.shell.js,
|
49
107
|
and any [path]s given. Simply type "quit" or "exit" to
|
50
108
|
terminate the shell.'
|
51
109
|
c.example 'Run shell', 'jspec shell'
|
@@ -54,256 +112,67 @@ command :shell do |c|
|
|
54
112
|
c.when_called do |args, options|
|
55
113
|
paths = ['jspec.js', 'jspec.shell.js'] | args
|
56
114
|
paths.map! do |path|
|
57
|
-
if path.include? 'jspec'
|
115
|
+
if path.include? 'jspec.'
|
58
116
|
"-f #{JSPEC_ROOT}/lib/#{path}"
|
59
117
|
else
|
60
118
|
"-f #{path}"
|
61
119
|
end
|
62
120
|
end
|
63
121
|
say "JSpec #{program(:version)}"
|
64
|
-
`#{RHINO} #{paths.join(' ')} -f -`
|
122
|
+
`#{JSpec::Project::RHINO} #{paths.join(' ')} -f -`
|
65
123
|
end
|
66
124
|
end
|
67
125
|
|
68
126
|
command :update do |c|
|
69
|
-
c.syntax = 'jspec update [
|
127
|
+
c.syntax = 'jspec update [dest]'
|
70
128
|
c.summary = 'Update JSpec releases'
|
71
|
-
c.description = 'Update JSpec release
|
72
|
-
the latest JSpec features. Execute from JSpec project
|
73
|
-
update the default template spec files.
|
129
|
+
c.description = 'Update JSpec release relative to [dest], this will allow you
|
130
|
+
to utilize the latest JSpec features. Execute from JSpec project
|
131
|
+
root without [dest] to update the default template spec files.
|
132
|
+
|
133
|
+
This command supports regular projects, as well as those initialized
|
134
|
+
with --symlink and --freeze.'
|
135
|
+
c.example 'Update project in the current directory', 'jspec update'
|
136
|
+
c.example 'Update project in the directory specified', 'jspec update path/to/project'
|
74
137
|
c.when_called do |args, options|
|
75
|
-
|
76
|
-
if rails?
|
77
|
-
paths = 'jspec/spec.dom.html', 'jspec/spec.rhino.js'
|
78
|
-
else
|
79
|
-
paths = 'spec/spec.dom.html', 'spec/spec.rhino.js'
|
80
|
-
end
|
81
|
-
else
|
82
|
-
paths = args
|
83
|
-
end
|
84
|
-
update_version_in *paths
|
138
|
+
JSpec::Project.for(dest = args.shift || '.').update!
|
85
139
|
end
|
86
140
|
end
|
87
141
|
|
88
142
|
command :run do |c|
|
89
143
|
c.syntax = 'jspec run [path] [options]'
|
90
144
|
c.summary = 'Run specifications'
|
91
|
-
c.description = 'Run specifications, defaulting [path] to spec/
|
145
|
+
c.description = 'Run specifications, defaulting [path] to spec/dom.html.
|
92
146
|
You will need to supply [path] if your specs do not reside
|
93
147
|
in this location. `run --bind` is the default sub-command of
|
94
148
|
jspec so you may simply execute `jspec` in order to bind execution
|
95
149
|
of your specs when a file is altered.
|
96
150
|
|
97
|
-
|
98
|
-
to be spec/
|
99
|
-
|
151
|
+
Rhino:
|
152
|
+
The [path] is assumed to be spec/rhino.js unless specified.
|
153
|
+
|
154
|
+
Node.js:
|
155
|
+
The [path] is assumed to be spec/node.js unless specified.
|
100
156
|
|
101
157
|
JSpec\'s server is also available via --server, which defaults
|
102
158
|
the [path] to spec/server.html'
|
103
|
-
c.example 'Run once in
|
159
|
+
c.example 'Run once in default browser', 'jspec run'
|
104
160
|
c.example 'Run once in Safari and Firefox', 'jspec run --browsers Safari,Firefox'
|
105
161
|
c.example 'Run once in Opera, Firefox, and Chrome', 'jspec run --browsers opera,ff,chrome'
|
106
162
|
c.example 'Run custom spec file', 'jspec run foo.html'
|
107
163
|
c.example 'Auto-run browsers when a file is altered', 'jspec run --bind --browsers Safari,Firefox'
|
108
164
|
c.example 'Shortcut for the previous example', 'jspec --browsers Safari,Firefox'
|
165
|
+
c.example 'Run Rhino specs', 'jspec run --rhino'
|
109
166
|
c.example 'Auto-run rhino when a file is altered', 'jspec --rhino'
|
110
|
-
c.example 'Run Rhino specs at spec/rhino.js', 'jspec run --rhino'
|
111
|
-
c.example 'Run Rhino specs once', 'jspec run specs/something.js --rhino'
|
112
167
|
c.option '-b', '--browsers BROWSERS', Array, 'Specify browsers to test'
|
113
168
|
c.option '-p', '--paths PATHS', Array, 'Specify paths when binding, defaults to javascript within ./lib and ./spec'
|
114
169
|
c.option '-B', '--bind', 'Auto-run specs when source files or specs are altered'
|
115
170
|
c.option '-R', '--rhino', 'Run specs using Rhino'
|
171
|
+
c.option '-N', '--node', 'Run specs using Node.js'
|
116
172
|
c.option '-S', '--server', 'Run specs using the JSpec server'
|
117
173
|
c.option '-P', '--port NUMBER', Integer, 'Start JSpec server using the given port number'
|
118
174
|
c.when_called do |args, options|
|
119
|
-
|
120
|
-
# Rails
|
121
|
-
if rails?
|
122
|
-
options.default :paths => ['public/javascripts/**/*.js', 'jspec/**/*.js'], :port => 4444
|
123
|
-
else
|
124
|
-
options.default :paths => ['lib/**/*.js', 'spec/**/*.js'], :port => 4444
|
125
|
-
end
|
126
|
-
|
127
|
-
# Actions
|
128
|
-
if options.rhino
|
129
|
-
suite = args.shift || path_to('spec.rhino.js')
|
130
|
-
action = lambda { exit rhino(suite) }
|
131
|
-
elsif options.server
|
132
|
-
raise 'Cannot use --server with --bind' if options.bind
|
133
|
-
suite = args.shift || path_to('spec.server.html')
|
134
|
-
action = lambda { start_server suite, options }
|
135
|
-
else
|
136
|
-
suite = args.shift || path_to('spec.dom.html')
|
137
|
-
browsers = browsers_for options.browsers || ['safari']
|
138
|
-
action = lambda do
|
139
|
-
browsers.each do |browser|
|
140
|
-
browser.visit File.expand_path(suite)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# Binding
|
146
|
-
if options.bind
|
147
|
-
listener = Bind::Listener.new :paths => options.paths, :interval => 1, :actions => [action], :debug => $stdout
|
148
|
-
listener.run!
|
149
|
-
else
|
150
|
-
action.call File.new(suite)
|
151
|
-
end
|
175
|
+
JSpec::Project.for('.').run! args.first, options.__hash__
|
152
176
|
end
|
153
177
|
end
|
154
178
|
alias_command :bind, :run, '--bind'
|
155
|
-
|
156
|
-
##
|
157
|
-
# Initialize template at _dest_.
|
158
|
-
|
159
|
-
def initialize_at dest, options
|
160
|
-
unless Dir[dest + '/*'].empty?
|
161
|
-
abort unless agree "'#{dest}' is not empty; continue? "
|
162
|
-
end
|
163
|
-
|
164
|
-
copy_template_to 'default', dest
|
165
|
-
setup_lib_dir dest, options
|
166
|
-
replace_root_in dest, 'spec/spec.dom.html', 'spec/spec.rhino.js'
|
167
|
-
end
|
168
|
-
|
169
|
-
##
|
170
|
-
# Initialize rails template at _dest_.
|
171
|
-
|
172
|
-
def initialize_rails_at dest, options
|
173
|
-
unless looks_like_rails_root?(dest)
|
174
|
-
abort unless agree "'#{dest}' does not look like root of a rails project; continue? "
|
175
|
-
end
|
176
|
-
|
177
|
-
copy_template_to 'rails', "#{dest}/jspec"
|
178
|
-
setup_lib_dir "#{dest}/jspec", options
|
179
|
-
replace_root_in "#{dest}/jspec", 'spec.dom.html', 'spec.rhino.js'
|
180
|
-
end
|
181
|
-
|
182
|
-
##
|
183
|
-
# Copy template _name_ to _dest_.
|
184
|
-
|
185
|
-
def copy_template_to name, dest
|
186
|
-
FileUtils.mkdir_p dest
|
187
|
-
FileUtils.cp_r path_to_template(name), dest
|
188
|
-
end
|
189
|
-
|
190
|
-
##
|
191
|
-
# Return path to template _name_.
|
192
|
-
|
193
|
-
def path_to_template name
|
194
|
-
File.join JSPEC_ROOT, 'templates', name, '.'
|
195
|
-
end
|
196
|
-
|
197
|
-
##
|
198
|
-
# Resolve path to _file_. Supports rails and unbound projects.
|
199
|
-
|
200
|
-
def path_to file
|
201
|
-
rails? ? "jspec/#{file}" : "spec/#{file}"
|
202
|
-
end
|
203
|
-
|
204
|
-
##
|
205
|
-
# Execute _file_ with Rhino.
|
206
|
-
|
207
|
-
def rhino file
|
208
|
-
raise "#{file} not found" unless File.exists? file
|
209
|
-
system "#{RHINO} #{file}"
|
210
|
-
end
|
211
|
-
|
212
|
-
##
|
213
|
-
# Start server with _suite_ html and _options_.
|
214
|
-
|
215
|
-
def start_server suite, options
|
216
|
-
set :port, options.port
|
217
|
-
set :server, 'Mongrel'
|
218
|
-
enable :sessions
|
219
|
-
disable :logging
|
220
|
-
hook = File.expand_path path_to('server.rb')
|
221
|
-
load hook if File.exists? hook
|
222
|
-
JSpec::Server.new(suite, options.port).start(options.browsers ? browsers_for(options.browsers) : nil)
|
223
|
-
end
|
224
|
-
|
225
|
-
##
|
226
|
-
# Return array of browser instances for the given _names_.
|
227
|
-
|
228
|
-
def browsers_for names
|
229
|
-
names.map do |name|
|
230
|
-
begin
|
231
|
-
Browser.subclasses.find do |browser|
|
232
|
-
browser.matches_name? name
|
233
|
-
end.new
|
234
|
-
rescue
|
235
|
-
raise "Unsupported browser `#{name}'"
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
##
|
241
|
-
# Check if the current directory looks like a rails app.
|
242
|
-
|
243
|
-
def rails?
|
244
|
-
File.directory? 'jspec'
|
245
|
-
end
|
246
|
-
|
247
|
-
##
|
248
|
-
# Replace JSPEC_ROOT placeholder in _paths_ relative to _dest_.
|
249
|
-
|
250
|
-
def replace_root_in dest, *paths
|
251
|
-
if rails? && File.exist?("#{dest}/jspec/lib")
|
252
|
-
root = './jspec'
|
253
|
-
elsif File.exist?("#{dest}/spec/lib")
|
254
|
-
root = "./spec"
|
255
|
-
else
|
256
|
-
root = JSPEC_ROOT
|
257
|
-
end
|
258
|
-
|
259
|
-
paths.each do |path|
|
260
|
-
path = File.join dest, path
|
261
|
-
if path.include? 'dom'
|
262
|
-
contents = File.read(path).gsub 'JSPEC_ROOT/', root == JSPEC_ROOT ? "#{JSPEC_ROOT}/" : ''
|
263
|
-
else
|
264
|
-
contents = File.read(path).gsub 'JSPEC_ROOT', root
|
265
|
-
end
|
266
|
-
File.open(path, 'w') { |file| file.write contents }
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
##
|
271
|
-
# Update JSpec version in _paths_. Matches jspec-TRIPLE
|
272
|
-
|
273
|
-
def update_version_in *paths
|
274
|
-
paths.each do |path|
|
275
|
-
next unless File.exists? path
|
276
|
-
contents = File.read(path).gsub /jspec-(\d+\.\d+\.\d+)/, "jspec-#{program(:version)}"
|
277
|
-
File.open(path, 'r+'){ |file| file.write contents }
|
278
|
-
say "Updated #{path}; #{$1} -> #{program(:version)}"
|
279
|
-
end
|
280
|
-
say "Finished updating JSpec"
|
281
|
-
end
|
282
|
-
|
283
|
-
##
|
284
|
-
# Check if _path_ looks like a rails root directory.
|
285
|
-
|
286
|
-
def looks_like_rails_root? path = '.'
|
287
|
-
File.directory? "#{path}/vendor"
|
288
|
-
end
|
289
|
-
|
290
|
-
##
|
291
|
-
# Copy or symlink library to the specified path.
|
292
|
-
|
293
|
-
def setup_lib_dir dest, options
|
294
|
-
return unless options.symlink || options.freeze
|
295
|
-
|
296
|
-
if rails?
|
297
|
-
dest = File.join dest, "lib"
|
298
|
-
else
|
299
|
-
dest = File.join dest, "spec", "lib"
|
300
|
-
end
|
301
|
-
|
302
|
-
from = File.join JSPEC_ROOT, "lib"
|
303
|
-
|
304
|
-
if options.symlink
|
305
|
-
FileUtils.symlink from, dest, :force => true
|
306
|
-
else
|
307
|
-
FileUtils.cp_r from, dest
|
308
|
-
end
|
309
|
-
end
|