diff --git a/.idea/dictionaries/pivotal.xml b/.idea/dictionaries/pivotal.xml new file mode 100644 index 00000000..ff8c9507 --- /dev/null +++ b/.idea/dictionaries/pivotal.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Rakefile b/Rakefile index d49c455c..f5c21ad6 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/bin/jasmine b/bin/jasmine index baa1b603..b0f874fc 100755 --- a/bin/jasmine +++ b/bin/jasmine @@ -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 diff --git a/generators/jasmine/templates/lib/tasks/jasmine.rake b/generators/jasmine/templates/lib/tasks/jasmine.rake index 612f159b..d2cc00be 100644 --- a/generators/jasmine/templates/lib/tasks/jasmine.rake +++ b/generators/jasmine/templates/lib/tasks/jasmine.rake @@ -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' \ No newline at end of file diff --git a/generators/jasmine/templates/spec/javascripts/support/jasmine.yml b/generators/jasmine/templates/spec/javascripts/support/jasmine.yml index 721c7321..7cce692d 100644 --- a/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +++ b/generators/jasmine/templates/spec/javascripts/support/jasmine.yml @@ -11,6 +11,7 @@ # - dist/**/*.js # src_files: + - public/javascripts/**/*.js # stylesheets # diff --git a/jasmine b/jasmine index ed80a0ca..7a69d646 160000 --- a/jasmine +++ b/jasmine @@ -1 +1 @@ -Subproject commit ed80a0cad7ebd593d722aa920ce70c91a846fc33 +Subproject commit 7a69d6466902ad90cc2f1f63f1b21bf605199961 diff --git a/jasmine.gemspec b/jasmine.gemspec index a531c923..7a15c974 100644 --- a/jasmine.gemspec +++ b/jasmine.gemspec @@ -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" ] diff --git a/lib/jasmine.rb b/lib/jasmine.rb index 95f803f4..8b1a9042 100644 --- a/lib/jasmine.rb +++ b/lib/jasmine.rb @@ -3,4 +3,6 @@ require 'jasmine/server' require 'jasmine/selenium_driver' -require 'jasmine/spec_builder' \ No newline at end of file +require 'jasmine/spec_builder' + +require 'jasmine/command_line_tool' \ No newline at end of file diff --git a/lib/jasmine/command_line_tool.rb b/lib/jasmine/command_line_tool.rb new file mode 100644 index 00000000..db218461 --- /dev/null +++ b/lib/jasmine/command_line_tool.rb @@ -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 diff --git a/lib/jasmine/tasks/jasmine.rake b/lib/jasmine/tasks/jasmine.rake new file mode 100644 index 00000000..612f159b --- /dev/null +++ b/lib/jasmine/tasks/jasmine.rake @@ -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'] diff --git a/spec/jasmine_command_line_tool_spec.rb b/spec/jasmine_command_line_tool_spec.rb new file mode 100644 index 00000000..3b3e75fb --- /dev/null +++ b/spec/jasmine_command_line_tool_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dc3123fa..12751421 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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"