Permalink
Browse files

Add rails generators. Add sources.yaml support. Fix Prototype.js coll…

…ision on jasmine:ci. Version bump to 0.4.0.
  • Loading branch information...
1 parent d2fe23b commit 53305edc689dea34c227336b08fa8e3e6038e3a5 @ragaskar ragaskar committed Jan 26, 2010
View
@@ -1,5 +1,5 @@
---
-:minor: 1
-:build:
-:patch: 3
+:patch: 0
:major: 0
+:build:
+:minor: 4
View
@@ -10,45 +10,46 @@ def expand(*paths)
File.expand_path(File.join(*paths))
end
-def rakefile_path
- expand(cwd, 'templates/Rakefile')
+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/helpers')
+ File.makedirs('spec/javascripts/support')
- dest_root = File.expand_path(Dir.pwd)
- dest_spec = expand(dest_root, 'spec')
- dest_spec_javascripts = expand(dest_root, 'spec/javascripts')
- dest_spec_helpers = expand(dest_root, 'spec/helpers')
+ copy_unless_exists('spec/javascripts/SpecHelper.js')
+ copy_unless_exists('spec/javascripts/ExampleSpec.js')
+ copy_unless_exists('spec/javascripts/support/jasmine_config.rb')
+ copy_unless_exists('spec/javascripts/support/jasmine_spec.rb')
- unless File.exist?(expand(dest_spec_helpers, 'spec_helper.js'))
- 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')
+ rails_tasks_dir = dest_path('lib/tasks')
if File.exist?(rails_tasks_dir)
- File.makedirs('lib/tasks/jasmine')
- File.copy(rakefile_path, File.join(rails_tasks_dir, 'jasmine/jasmine.rake'))
+ copy_unless_exists('lib/tasks/jasmine.rake')
+ copy_unless_exists('spec/javascripts/support/sources-rails.yaml', 'spec/javascripts/support/sources.yaml')
else
- if File.exist?(expand(dest_root, 'Rakefile'))
- existing_rakefile = expand(dest_root, 'Rakefile')
- load existing_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)
+ copy_unless_exists('spec/javascripts/support/sources.yaml')
+ if File.exist?(dest_path('Rakefile'))
+ load dest_path('Rakefile')
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
@@ -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
@@ -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
@@ -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']
@@ -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
View
@@ -5,19 +5,28 @@
Gem::Specification.new do |s|
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.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.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 = [
"README.markdown"
]
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_spec_builder.rb",
"jasmine/contrib/ruby/run.html",
@@ -29,13 +38,10 @@ Gem::Specification.new do |s|
"lib/jasmine.rb",
"lib/jasmine/base.rb",
"lib/jasmine/config.rb",
- "lib/jasmine/jasmine_helper.rb",
- "lib/jasmine/jasmine_meta_spec.rb",
"lib/jasmine/run.html.erb",
"lib/jasmine/selenium_driver.rb",
"lib/jasmine/server.rb",
- "lib/jasmine/spec_builder.rb",
- "templates/Rakefile"
+ "lib/jasmine/spec_builder.rb"
]
s.homepage = %q{http://github.com/pivotal/jasmine-ruby}
s.rdoc_options = ["--charset=UTF-8"]
View
@@ -3,5 +3,4 @@
require 'jasmine/server'
require 'jasmine/selenium_driver'
-require 'jasmine/jasmine_helper'
require 'jasmine/spec_builder'
View
@@ -1,5 +1,7 @@
module Jasmine
class Config
+ require 'yaml'
+
def initialize(options = {})
require 'selenium_rc'
@selenium_jar_path = SeleniumRC::Server.allocate.jar_path
@@ -86,31 +88,60 @@ def match_files(dir, pattern)
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
end
- def src_files
- match_files(src_dir, "**/*.js")
+ def project_root
+ Dir.pwd
end
- def src_path
- "src"
+ def src_dir
+ if simple_config['src_dir']
+ File.join(project_root, simple_config['src_dir'])
+ else
+ project_root
+ end
end
- def spec_path
- "spec"
+ def simple_config_file
+ 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
def spec_files
match_files(spec_dir, "**/*.js")
end
+ def spec_path
+ "/__spec__"
+ end
+
+ def root_path
+ "/__root__"
+ end
+
def mappings
{
- "/" + src_path => src_dir,
- "/" + spec_path => spec_dir
+ spec_path => spec_dir,
+ root_path => project_root
}
end
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
def spec_files_full_paths
@@ -1,48 +0,0 @@
-class JasmineHelper
- def self.lib_dir
- File.expand_path(File.join(root, 'lib'))
- end
-
- def self.jasmine
- ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.lib_dir}/jasmine*.js").first)] +
- ['/lib/json2.js',
- '/lib/TrivialReporter.js']
- end
-
- def self.root
- File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine'))
- end
-
- def self.spec_dir
- File.expand_path('spec')
- end
-
- def self.spec_files
- Dir.glob(File.join(spec_dir, "javascripts/**/*[Ss]pec.js"))
- end
-
- def self.specs
- spec_files.collect {|f| f.sub(spec_dir, "/spec")}
- end
-
- def self.spec_helpers_files
- Dir.glob(File.join(spec_dir, "helpers/**/*.js"))
- end
-
- def self.spec_helpers
- spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")}
- end
-
- def self.meta_spec_path
- File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine', 'jasmine_meta_spec.rb'))
- end
-
- def self.files
- []
- end
-
- def self.stylesheets
- []
- end
-
-end
Oops, something went wrong.

0 comments on commit 53305ed

Please sign in to comment.