Permalink
Browse files

Refactored jasmine command line tool.

Added spec for jasmine command line tool.
  • Loading branch information...
1 parent 920e918 commit 183ad8f1bcf8430b8674f8d3abbca37092fb9e5a Lee Byrd & Christian Williams committed Jun 25, 2010
@@ -0,0 +1,3 @@
+<component name="ProjectDictionaryState">
+ <dictionary name="pivotal" />
+</component>
View
@@ -30,7 +30,7 @@ namespace :jeweler do
end
# copy jasmine's example tree into our generator templates dir
- FileUtils.rm_r('generators/jasmine/templates/jasmine-example')
+ FileUtils.rm_r('generators/jasmine/templates/jasmine-example', :force => true)
FileUtils.cp_r('jasmine/example', 'generators/jasmine/templates/jasmine-example')
begin
View
@@ -1,58 +1,6 @@
#!/usr/bin/env ruby
-require 'rubygems'
-require 'rake'
-
-def cwd
- File.expand_path(File.join(File.dirname(__FILE__), '..'))
-end
-
-def expand(*paths)
- File.expand_path(File.join(*paths))
-end
-
-def template_path(filepath)
- expand(cwd, File.join("generators/jasmine/templates", filepath))
-end
-
-def dest_path(filepath)
- expand(Dir.pwd, filepath)
-end
-def copy_unless_exists(relative_path, dest_path = nil)
- unless File.exist?(dest_path(relative_path))
- File.copy(template_path(relative_path), dest_path(dest_path || relative_path))
- end
-end
-
-if ARGV[0] == 'init'
- require 'ftools'
- File.makedirs('spec/javascripts')
- File.makedirs('spec/javascripts/support')
- File.makedirs('spec/javascripts/helpers')
-
- copy_unless_exists('spec/javascripts/helpers/SpecHelper.js')
- copy_unless_exists('spec/javascripts/ExampleSpec.js')
- copy_unless_exists('spec/javascripts/support/jasmine_runner.rb')
-
- rails_tasks_dir = dest_path('lib/tasks')
- if File.exist?(rails_tasks_dir)
- copy_unless_exists('lib/tasks/jasmine.rake')
- copy_unless_exists('spec/javascripts/support/jasmine-rails.yml', 'spec/javascripts/support/jasmine.yml')
- else
- copy_unless_exists('spec/javascripts/support/jasmine.yml')
- write_mode = 'w'
- if File.exist?(dest_path('Rakefile'))
- load dest_path('Rakefile')
- write_mode = 'a'
- end
- unless Rake::Task.task_defined?('jasmine')
- File.open(dest_path('Rakefile'), write_mode) do |f|
- f.write(File.read(template_path('lib/tasks/jasmine.rake')))
- end
- end
- end
- File.open(template_path('INSTALL'), 'r').each_line do |line|
- puts line
- end
-end
+require 'rubygems'
+require 'jasmine'
+Jasmine::CommandLineTool.new.process ARGV
@@ -1,31 +1 @@
-namespace :jasmine do
- task :require do
- require 'jasmine'
- end
-
- desc "Run continuous integration tests"
- task :ci => "jasmine:require" do
- require "spec"
- require 'spec/rake/spectask'
-
- Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
- t.spec_opts = ["--color", "--format", "specdoc"]
- t.verbose = true
- t.spec_files = ['spec/javascripts/support/jasmine_runner.rb']
- end
- Rake::Task["jasmine_continuous_integration_runner"].invoke
- end
-
- task :server => "jasmine:require" do
- jasmine_config_overrides = 'spec/javascripts/support/jasmine_config.rb'
- require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
-
- puts "your tests are here:"
- puts " http://localhost:8888/"
-
- Jasmine::Config.new.start_server
- end
-end
-
-desc "Run specs via server"
-task :jasmine => ['jasmine:server']
+load 'jasmine/tasks/jasmine.rake'
@@ -11,6 +11,7 @@
# - dist/**/*.js
#
src_files:
+ - public/javascripts/**/*.js
# stylesheets
#
View
@@ -37,11 +37,13 @@ Gem::Specification.new do |s|
"jasmine/lib/json2.js",
"lib/jasmine.rb",
"lib/jasmine/base.rb",
+ "lib/jasmine/command_line_tool.rb",
"lib/jasmine/config.rb",
"lib/jasmine/run.html.erb",
"lib/jasmine/selenium_driver.rb",
"lib/jasmine/server.rb",
- "lib/jasmine/spec_builder.rb"
+ "lib/jasmine/spec_builder.rb",
+ "lib/jasmine/tasks/jasmine.rake"
]
s.homepage = %q{http://github.com/pivotal/jasmine-ruby}
s.rdoc_options = ["--charset=UTF-8"]
@@ -50,8 +52,10 @@ Gem::Specification.new do |s|
s.summary = %q{Jasmine Ruby Runner}
s.test_files = [
"spec/config_spec.rb",
+ "spec/jasmine_command_line_tool_spec.rb",
"spec/jasmine_self_test_config.rb",
"spec/jasmine_self_test_spec.rb",
+ "spec/rails_generator_spec.rb",
"spec/server_spec.rb",
"spec/spec_helper.rb"
]
View
@@ -3,4 +3,6 @@
require 'jasmine/server'
require 'jasmine/selenium_driver'
-require 'jasmine/spec_builder'
+require 'jasmine/spec_builder'
+
+require 'jasmine/command_line_tool'
@@ -0,0 +1,67 @@
+module Jasmine
+ class CommandLineTool
+ def cwd
+ File.expand_path(File.join(File.dirname(__FILE__), '../..'))
+ end
+
+ def expand(*paths)
+ File.expand_path(File.join(*paths))
+ end
+
+ def template_path(filepath)
+ expand(cwd, File.join("generators/jasmine/templates", filepath))
+ end
+
+ def dest_path(filepath)
+ expand(Dir.pwd, filepath)
+ end
+
+ def copy_unless_exists(relative_path, dest_path = nil)
+ unless File.exist?(dest_path(relative_path))
+ File.copy(template_path(relative_path), dest_path(dest_path || relative_path))
+ end
+ end
+
+ def process(argv)
+ if argv[0] == 'init'
+ require 'ftools'
+ File.makedirs('public/javascripts')
+ File.makedirs('spec/javascripts')
+ File.makedirs('spec/javascripts/support')
+ File.makedirs('spec/javascripts/helpers')
+
+ copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
+ copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
+ copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
+ copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
+ copy_unless_exists('spec/javascripts/support/jasmine_runner.rb')
+
+ rails_tasks_dir = dest_path('lib/tasks')
+ if File.exist?(rails_tasks_dir)
+ copy_unless_exists('lib/tasks/jasmine.rake')
+ copy_unless_exists('spec/javascripts/support/jasmine-rails.yml', 'spec/javascripts/support/jasmine.yml')
+ else
+ copy_unless_exists('spec/javascripts/support/jasmine.yml')
+ write_mode = 'w'
+ if File.exist?(dest_path('Rakefile'))
+ load dest_path('Rakefile')
+ write_mode = 'a'
+ end
+
+ require 'rake'
+ unless Rake::Task.task_defined?('jasmine')
+ File.open(dest_path('Rakefile'), write_mode) do |f|
+ f.write(File.read(template_path('lib/tasks/jasmine.rake')))
+ end
+ end
+ end
+ File.open(template_path('INSTALL'), 'r').each_line do |line|
+ puts line
+ end
+ else
+ puts "unknown command #{argv}"
+ puts "Usage: jasmine init"
+ end
+ end
+ end
+end
@@ -0,0 +1,31 @@
+namespace :jasmine do
+ task :require do
+ require 'jasmine'
+ end
+
+ desc "Run continuous integration tests"
+ task :ci => "jasmine:require" do
+ require "spec"
+ require 'spec/rake/spectask'
+
+ Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
+ t.spec_opts = ["--color", "--format", "specdoc"]
+ t.verbose = true
+ t.spec_files = ['spec/javascripts/support/jasmine_runner.rb']
+ end
+ Rake::Task["jasmine_continuous_integration_runner"].invoke
+ end
+
+ task :server => "jasmine:require" do
+ jasmine_config_overrides = 'spec/javascripts/support/jasmine_config.rb'
+ require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
+
+ puts "your tests are here:"
+ puts " http://localhost:8888/"
+
+ Jasmine::Config.new.start_server
+ end
+end
+
+desc "Run specs via server"
+task :jasmine => ['jasmine:server']
@@ -0,0 +1,30 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
+
+def create_temp_dir
+ tmp = File.join(Dir.tmpdir, 'jasmine-gem-test')
+ FileUtils.rm_r(tmp, :force => true)
+ FileUtils.mkdir(tmp)
+ tmp
+end
+
+describe "Jasmine command line tool" do
+ before :each do
+ @old_dir = Dir::pwd
+ @tmp = create_temp_dir
+ Dir::chdir @tmp
+ end
+
+ after :each do
+ Dir::chdir @old_dir
+ end
+
+ it "should create files on init" do
+ Jasmine::CommandLineTool.new.process ["init"]
+
+ my_jasmine_lib = File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
+ bootstrap = "$:.unshift('#{my_jasmine_lib}')"
+
+ ci_output = `rake -E \"#{bootstrap}\" --trace jasmine:ci`
+ ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
+ end
+end
View
@@ -5,4 +5,6 @@
require 'spec'
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/jasmine"))
+$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../lib")))
+
+require "jasmine"

0 comments on commit 183ad8f

Please sign in to comment.