bin/jspec in visionmedia-jspec-2.10.0 vs bin/jspec in visionmedia-jspec-2.11.0

- old
+ new

@@ -10,33 +10,63 @@ require 'server/server' RHINO = 'java org.mozilla.javascript.tools.shell.Main' program :name, 'JSpec' -program :version, '2.10.0' +program :version, '2.11.0' program :description, 'JavaScript BDD Testing Framework' default_command :bind command :init do |c| c.syntax = 'jspec init [dest]' c.summary = 'Initialize a JSpec project template' c.description = 'Initialize a JSpec project template. Defaults to the current directory when [dest] is not specified. The template includes several files for - running via Rhino, DOM, and the JSpec Rack server.' + running via Rhino, DOM, and the JSpec Rack server. + + Additional switches --freeze, and --symlink are available in order + to preserve the version of JSpec at the time of initialization. Otherwise + incompatibilities from later versions may prevent your suite from + running properly.' + c.option '-R', '--rails', 'Initialize rails template from rails root directory' + c.option '-f', '--freeze', 'Copy the JSpec library' + c.option '-s', '--symlink', 'Symlink the JSpec library instead of copying it' c.example 'Create a directory foo, initialized with a jspec template', 'jspec init foo' - c.option '-R', '--rails', 'Initialize rails template' c.when_called do |args, options| dest = args.shift || '.' if options.rails - initialize_rails_at dest + initialize_rails_at dest, options else - initialize_at dest + initialize_at dest, options end - say "Template initialized at '#{dest}'" + say "Template initialized at `#{dest}'" end end +command :shell do |c| + c.syntax = 'jspec shell [path ...]' + c.summary = 'JSpec interactive shell' + c.description = 'Launch interactive shell with jspec.js, jspec.shell.js, + and any [path]s given. Simply type "quit" or "exit" to + terminate the shell.' + c.example 'Run shell', 'jspec shell' + c.example 'Run shell with glob of files', 'jspec shell lib/*.js' + c.example 'Run shell with list of files', 'jspec shell lib/foo.js lib/bar.js' + c.when_called do |args, options| + paths = ['jspec.js', 'jspec.shell.js'] | args + paths.map! do |path| + if path.include? 'jspec' + "-f #{JSPEC_ROOT}/lib/#{path}" + else + "-f #{path}" + end + end + say "JSpec #{program(:version)}" + `#{RHINO} #{paths.join(' ')} -f -` + end +end + command :update do |c| c.syntax = 'jspec update [path ...]' c.summary = 'Update JSpec releases' c.description = 'Update JSpec release in [paths], this will allow you to utilize the latest JSpec features. Execute from JSpec project root without [paths] to @@ -124,26 +154,30 @@ alias_command :bind, :run, '--bind' ## # Initialize template at _dest_. -def initialize_at dest +def initialize_at dest, options unless Dir[dest + '/*'].empty? abort unless agree "'#{dest}' is not empty; continue? " end + copy_template_to 'default', dest + setup_lib_dir dest, options replace_root_in dest, 'spec/spec.dom.html', 'spec/spec.rhino.js' end ## # Initialize rails template at _dest_. -def initialize_rails_at dest +def initialize_rails_at dest, options unless looks_like_rails_root?(dest) abort unless agree "'#{dest}' does not look like root of a rails project; continue? " end + copy_template_to 'rails', "#{dest}/jspec" + setup_lib_dir "#{dest}/jspec", options replace_root_in "#{dest}/jspec", 'spec.dom.html', 'spec.rhino.js' end ## # Copy template _name_ to _dest_. @@ -212,13 +246,21 @@ ## # Replace JSPEC_ROOT placeholder in _paths_ relative to _dest_. def replace_root_in dest, *paths + if rails? && File.exist?("#{dest}/jspec/lib") + root = "." + elsif File.exist?("#{dest}/spec/lib") + root = "." + else + root = JSPEC_ROOT + end + paths.each do |path| path = File.join dest, path - contents = File.read(path).gsub 'JSPEC_ROOT', JSPEC_ROOT + contents = File.read(path).gsub 'JSPEC_ROOT', root File.open(path, 'w') { |file| file.write contents } end end ## @@ -237,6 +279,27 @@ ## # Check if _path_ looks like a rails root directory. def looks_like_rails_root? path = '.' File.directory? "#{path}/vendor" +end + +## +# Copy or symlink library to the specified path. + +def setup_lib_dir dest, options + return unless options.symlink || options.freeze + + if rails? + dest = File.join dest, "lib" + else + dest = File.join dest, "spec", "lib" + end + + from = File.join JSPEC_ROOT, "lib" + + if options.symlink + FileUtils.symlink from, dest, :force => true + else + FileUtils.cp_r from, dest + end end