Skip to content

Commit

Permalink
Add rails generators. Add sources.yaml support. Fix Prototype.js coll…
Browse files Browse the repository at this point in the history
…ision on jasmine:ci. Version bump to 0.4.0.
  • Loading branch information
ragaskar committed Jan 26, 2010
1 parent d2fe23b commit 53305ed
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 214 deletions.
6 changes: 3 additions & 3 deletions VERSION.yml
@@ -1,5 +1,5 @@
--- ---
:minor: 1 :patch: 0
:build:
:patch: 3
:major: 0 :major: 0
:build:
:minor: 4
59 changes: 30 additions & 29 deletions bin/jasmine
Expand Up @@ -10,45 +10,46 @@ def expand(*paths)
File.expand_path(File.join(*paths)) File.expand_path(File.join(*paths))
end end


def rakefile_path def template_path(filepath)
expand(cwd, 'templates/Rakefile') 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 end


if ARGV[0] == 'init' if ARGV[0] == 'init'
require 'ftools' require 'ftools'
File.makedirs('spec/javascripts') File.makedirs('spec/javascripts')
File.makedirs('spec/helpers') File.makedirs('spec/javascripts/support')


dest_root = File.expand_path(Dir.pwd) copy_unless_exists('spec/javascripts/SpecHelper.js')
dest_spec = expand(dest_root, 'spec') copy_unless_exists('spec/javascripts/ExampleSpec.js')
dest_spec_javascripts = expand(dest_root, 'spec/javascripts') copy_unless_exists('spec/javascripts/support/jasmine_config.rb')
dest_spec_helpers = expand(dest_root, 'spec/helpers') copy_unless_exists('spec/javascripts/support/jasmine_spec.rb')


unless File.exist?(expand(dest_spec_helpers, 'spec_helper.js')) rails_tasks_dir = dest_path('lib/tasks')
File.copy(expand(cwd, 'templates/spec_helper.js'), dest_spec_helpers)
end
unless File.exist?(expand(dest_spec_helpers, 'jasmine_helper.rb'))
File.copy(expand(cwd, 'templates/jasmine_helper.rb'), dest_spec_helpers)
end

File.copy(expand(cwd, 'templates/example_spec.js'), dest_spec_javascripts)

rails_tasks_dir = expand(dest_root, 'lib', 'tasks')
if File.exist?(rails_tasks_dir) if File.exist?(rails_tasks_dir)
File.makedirs('lib/tasks/jasmine') copy_unless_exists('lib/tasks/jasmine.rake')
File.copy(rakefile_path, File.join(rails_tasks_dir, 'jasmine/jasmine.rake')) copy_unless_exists('spec/javascripts/support/sources-rails.yaml', 'spec/javascripts/support/sources.yaml')
else else
if File.exist?(expand(dest_root, 'Rakefile')) copy_unless_exists('spec/javascripts/support/sources.yaml')
existing_rakefile = expand(dest_root, 'Rakefile') if File.exist?(dest_path('Rakefile'))
load existing_rakefile load dest_path('Rakefile')
unless Rake::Task.task_defined?('jasmine')
open(existing_rakefile, 'a') do |f|
f.write(File.read(rakefile_path))
end
end
else
File.copy(rakefile_path, dest_root)
end end
write_mode = Rake::Task.task_defined?('jasmine') ? 'a' : 'w'
File.open(dest_path('Rakefile'), write_mode) do |f|
f.write(File.read(template_path('lib/tasks/jasmine.rake')))
end
end
File.open(template_path('INSTALL'), 'r').each_line do |line|
puts line
end end
end end


25 changes: 25 additions & 0 deletions generators/jasmine/jasmine_generator.rb
@@ -0,0 +1,25 @@
class JasmineGenerator < Rails::Generator::Base
def manifest
record do |m|

m.directory "spec/javascripts"
m.file "spec/javascripts/SpecHelper.js", "spec/javascripts/SpecHelper.js"
m.file "spec/javascripts/ExampleSpec.js", "spec/javascripts/ExampleSpec.js"

m.directory "spec/javascripts/support"
m.file "spec/javascripts/support/jasmine_config.rb", "spec/javascripts/support/jasmine_config.rb"
m.file "spec/javascripts/support/jasmine_spec.rb", "spec/javascripts/support/jasmine_spec.rb"
m.file "spec/javascripts/support/sources-rails.yaml", "spec/javascripts/support/sources.yaml"

m.directory "lib/tasks"
m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"

m.readme "INSTALL"
end
end

def file_name
"create_blog"
end

end
9 changes: 9 additions & 0 deletions generators/jasmine/templates/INSTALL
@@ -0,0 +1,9 @@
Jasmine has been installed with example specs.

To run the server:

rake jasmine

To run the automated CI task with Selenium:

rake jasmine:ci
23 changes: 23 additions & 0 deletions generators/jasmine/templates/lib/tasks/jasmine.rake
@@ -0,0 +1,23 @@
namespace :jasmine do
require 'jasmine'

desc "Run continuous integration tests"
require "spec"
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:ci) do |t|
t.spec_opts = ["--color", "--format", "specdoc"]
t.verbose = true
t.spec_files = ['spec/javascripts/support/jasmine_spec.rb']
end
task :server do
require 'spec/javascripts/support/jasmine_config'

puts "your tests are here:"
puts " http://localhost:8888/run.html"

Jasmine::Config.new.start_server
end
end

desc "Run specs via server"
task :jasmine => ['jasmine:server']
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,23 @@
require 'jasmine'

class Jasmine::Config

def project_root
File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."))
end

# Return an array of files to include before jasmine specs. Override if needed.
# def src_files
# match_files(src_dir, "**/*.js")
# end

# Path to your JavaScript source files
# def src_dir
# File.join(project_root, "public")
# end

# Path to your JavaScript specs
# def spec_dir
# File.join(project_root, 'spec/javascripts')
# end
end
@@ -0,0 +1,17 @@
require 'rubygems'
require File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config'))

jasmine_config = Jasmine::Config.new
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)

should_stop = false

Spec::Runner.configure do |config|
config.after(:suite) do
spec_builder.stop if should_stop
end
end

spec_builder.start
should_stop = true
spec_builder.declare_suites
@@ -0,0 +1,8 @@
sources:
- javascripts/prototype.js
- javascripts/effects.js
- javascripts/controls.js
- javascripts/dragdrop.js
- javascripts/application.js
src_dir: public
spec_dir: spec/javascripts
@@ -0,0 +1,5 @@
#sources:
# - lib/source1.js
# - lib/source2.js
#src_dir:
#spec_dir: spec/javascripts
22 changes: 14 additions & 8 deletions jasmine.gemspec
Expand Up @@ -5,19 +5,28 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{jasmine} s.name = %q{jasmine}
s.version = "0.1.3" s.version = "0.4.0"


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Rajan Agaskar", "Christian Williams"] s.authors = ["Rajan Agaskar", "Christian Williams"]
s.date = %q{2009-12-31} s.date = %q{2010-01-26}
s.default_executable = %q{jasmine}
s.description = %q{Javascript BDD test framework} s.description = %q{Javascript BDD test framework}
s.email = %q{ragaskar@gmail.com} s.email = %q{ragaskar@gmail.com}
s.executables = ["autospec", "edit_json.rb", "jasmine", "jeweler", "prettify_json.rb", "rackup", "rake", "rubyforge", "selenium-rc", "spec", "thin"] s.executables = ["jasmine"]
s.extra_rdoc_files = [ s.extra_rdoc_files = [
"README.markdown" "README.markdown"
] ]
s.files = [ s.files = [
"bin/jasmine", "generators/jasmine/jasmine_generator.rb",
"generators/jasmine/templates/INSTALL",
"generators/jasmine/templates/lib/tasks/jasmine.rake",
"generators/jasmine/templates/spec/javascripts/ExampleSpec.js",
"generators/jasmine/templates/spec/javascripts/SpecHelper.js",
"generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb",
"generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb",
"generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml",
"generators/jasmine/templates/spec/javascripts/support/sources.yaml",
"jasmine/contrib/ruby/jasmine_runner.rb", "jasmine/contrib/ruby/jasmine_runner.rb",
"jasmine/contrib/ruby/jasmine_spec_builder.rb", "jasmine/contrib/ruby/jasmine_spec_builder.rb",
"jasmine/contrib/ruby/run.html", "jasmine/contrib/ruby/run.html",
Expand All @@ -29,13 +38,10 @@ Gem::Specification.new do |s|
"lib/jasmine.rb", "lib/jasmine.rb",
"lib/jasmine/base.rb", "lib/jasmine/base.rb",
"lib/jasmine/config.rb", "lib/jasmine/config.rb",
"lib/jasmine/jasmine_helper.rb",
"lib/jasmine/jasmine_meta_spec.rb",
"lib/jasmine/run.html.erb", "lib/jasmine/run.html.erb",
"lib/jasmine/selenium_driver.rb", "lib/jasmine/selenium_driver.rb",
"lib/jasmine/server.rb", "lib/jasmine/server.rb",
"lib/jasmine/spec_builder.rb", "lib/jasmine/spec_builder.rb"
"templates/Rakefile"
] ]
s.homepage = %q{http://github.com/pivotal/jasmine-ruby} s.homepage = %q{http://github.com/pivotal/jasmine-ruby}
s.rdoc_options = ["--charset=UTF-8"] s.rdoc_options = ["--charset=UTF-8"]
Expand Down
1 change: 0 additions & 1 deletion lib/jasmine.rb
Expand Up @@ -3,5 +3,4 @@
require 'jasmine/server' require 'jasmine/server'
require 'jasmine/selenium_driver' require 'jasmine/selenium_driver'


require 'jasmine/jasmine_helper'
require 'jasmine/spec_builder' require 'jasmine/spec_builder'
49 changes: 40 additions & 9 deletions lib/jasmine/config.rb
@@ -1,5 +1,7 @@
module Jasmine module Jasmine
class Config class Config
require 'yaml'

def initialize(options = {}) def initialize(options = {})
require 'selenium_rc' require 'selenium_rc'
@selenium_jar_path = SeleniumRC::Server.allocate.jar_path @selenium_jar_path = SeleniumRC::Server.allocate.jar_path
Expand Down Expand Up @@ -86,31 +88,60 @@ def match_files(dir, pattern)
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
end end


def src_files def project_root
match_files(src_dir, "**/*.js") Dir.pwd
end end


def src_path def src_dir
"src" if simple_config['src_dir']
File.join(project_root, simple_config['src_dir'])
else
project_root
end
end end


def spec_path def simple_config_file
"spec" File.join(project_root, 'spec/javascripts/support/sources.yaml')
end

def simple_config
config = File.exist?(simple_config_file) ? File.open(simple_config_file) { |yf| YAML::load( yf ) } : false
config || {}
end

def src_files
simple_config['sources'] || []
end

def spec_dir
if simple_config['spec_dir']
File.join(project_root, simple_config['spec_dir'])
else
File.join(project_root, 'spec/javascripts')
end
end end


def spec_files def spec_files
match_files(spec_dir, "**/*.js") match_files(spec_dir, "**/*.js")
end end


def spec_path
"/__spec__"
end

def root_path
"/__root__"
end

def mappings def mappings
{ {
"/" + src_path => src_dir, spec_path => spec_dir,
"/" + spec_path => spec_dir root_path => project_root
} }
end end


def js_files def js_files
src_files.collect {|f| "/" + File.join(src_path, f) } + spec_files.collect {|f| "/" + File.join(spec_path, f) } src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) }
end end


def spec_files_full_paths def spec_files_full_paths
Expand Down
48 changes: 0 additions & 48 deletions lib/jasmine/jasmine_helper.rb

This file was deleted.

0 comments on commit 53305ed

Please sign in to comment.