Skip to content

Commit

Permalink
Refactored jasmine command line tool.
Browse files Browse the repository at this point in the history
Added spec for jasmine command line tool.
  • Loading branch information
Lee Byrd & Christian Williams committed Jun 25, 2010
1 parent 920e918 commit 183ad8f
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/pivotal.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 3 additions & 55 deletions bin/jasmine
Original file line number Diff line number Diff line change
@@ -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
32 changes: 1 addition & 31 deletions generators/jasmine/templates/lib/tasks/jasmine.rake
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# - dist/**/*.js
#
src_files:
- public/javascripts/**/*.js

# stylesheets
#
Expand Down
2 changes: 1 addition & 1 deletion jasmine
Submodule jasmine updated from ed80a0 to 7a69d6
6 changes: 5 additions & 1 deletion jasmine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
]
Expand Down
4 changes: 3 additions & 1 deletion lib/jasmine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
require 'jasmine/server'
require 'jasmine/selenium_driver'

require 'jasmine/spec_builder'
require 'jasmine/spec_builder'

require 'jasmine/command_line_tool'
67 changes: 67 additions & 0 deletions lib/jasmine/command_line_tool.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions lib/jasmine/tasks/jasmine.rake
Original file line number Diff line number Diff line change
@@ -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']
30 changes: 30 additions & 0 deletions spec/jasmine_command_line_tool_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.