Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Load jasmine_helper after configuring from yaml

- Allows users opportunity to add a Jasmine.configure block that
  overrides/augments jasmine.yml settings
- File defaults to specs/javascript/support/jasmine_helper.rb but is
  configurable from jasmine.yml
- *Only* processed if using jasmine.yml (which default rake tasks will
  do if jasmine.yml exists).
  • Loading branch information...
commit 63e8d46556a421cbb3b511b52cd8c2188d72b9db 1 parent 478c602
@ragaskar ragaskar authored
View
1  generators/jasmine/jasmine_generator.rb
@@ -14,6 +14,7 @@ def manifest
m.directory "spec/javascripts/support"
m.file "spec/javascripts/support/jasmine-rails.yml", "spec/javascripts/support/jasmine.yml"
+ m.file "spec/javascripts/support/jasmine_helper.rb", "spec/javascripts/support/jasmine_helper.rb"
m.readme "INSTALL"
m.directory "lib/tasks"
View
14 generators/jasmine/templates/spec/javascripts/support/jasmine.yml
@@ -72,3 +72,17 @@ src_dir:
# spec_dir: spec/javascripts
#
spec_dir:
+
+# spec_helper
+#
+# Ruby file that Jasmine server will require before starting.
+# Returned relative to your root path
+# Default spec/support/jasmine_helper.rb
+#
+# EXAMPLE:
+#
+# spec_helper: spec/support/jasmine_helper.rb
+#
+spec_helper: spec/support/jasmine_helper.rb
+
+
View
11 generators/jasmine/templates/spec/javascripts/support/jasmine_helper.rb
@@ -0,0 +1,11 @@
+#Use this file to set/override Jasmine configuration options
+#You can remove it if you don't need it.
+#This file is loaded *after* jasmine.yml is interpreted.
+#
+#Example: using a different boot file.
+#Jasmine.configure do |config|
+# @config.boot_dir = '/absolute/path/to/boot_dir'
+# @config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
+#end
+#
+
View
11 lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_helper.rb
@@ -0,0 +1,11 @@
+#Use this file to set/override Jasmine configuration options
+#You can remove it if you don't need it.
+#This file is loaded *after* jasmine.yml is interpreted.
+#
+#Example: using a different boot file.
+#Jasmine.configure do |config|
+# @config.boot_dir = '/absolute/path/to/boot_dir'
+# @config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
+#end
+#
+
View
1  lib/jasmine/command_line_tool.rb
@@ -37,6 +37,7 @@ def process(argv)
copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
copy_unless_exists('spec/javascripts/support/jasmine.yml')
+ copy_unless_exists('spec/javascripts/support/jasmine_helper.rb')
require 'rake'
write_mode = 'w'
if File.exist?(dest_path('Rakefile'))
View
2  lib/jasmine/config.rb
@@ -22,7 +22,6 @@ def self.initialize_config
@config.boot_files = lambda { core_config.boot_files }
@config.jasmine_files = lambda { core_config.js_files }
@config.jasmine_css_files = lambda { core_config.css_files }
-
@config.add_rack_path(jasmine_path, lambda { Rack::File.new(config.jasmine_dir) })
@config.add_rack_path(boot_path, lambda { Rack::File.new(config.boot_dir) })
@config.add_rack_path(spec_path, lambda { Rack::File.new(config.spec_dir) })
@@ -80,6 +79,7 @@ def self.load_configuration_from_yaml(path = nil)
config.src_dir = yaml_config.src_dir
config.spec_dir = yaml_config.spec_dir
end
+ require yaml_config.spec_helper if File.exist?(yaml_config.spec_helper)
end
end
View
4 lib/jasmine/yaml_config_parser.rb
@@ -46,6 +46,10 @@ def css_files
@path_expander.call(src_dir, loaded_yaml['stylesheets'] || [])
end
+ def spec_helper
+ File.join(@pwd, loaded_yaml['spec_helper'] || File.join('spec', 'javascripts', 'support', 'jasmine_helper.rb'))
+ end
+
private
def loaded_yaml
@yaml_loader.call(@path)
View
20 spec/yaml_config_parser_spec.rb
@@ -41,6 +41,26 @@
parser.jasmine_dir.should == File.join('some_project_root', 'some_jasmine_dir')
end
+ it "spec_helper returns default helper path when spec_helper is blank" do
+ yaml_loader = lambda do |path|
+ if path == "some_path"
+ {"spec_helper" => nil}
+ end
+ end
+ parser = Jasmine::YamlConfigParser.new('some_path', 'some_project_root', nil, yaml_loader)
+ parser.spec_helper.should == 'some_project_root/spec/javascripts/support/jasmine_helper.rb'
+ end
+
+ it "spec_helper returns spec_helper if set" do
+ yaml_loader = lambda do |path|
+ if path == "some_path"
+ {"spec_helper" => 'some_spec_helper.rb'}
+ end
+ end
+ parser = Jasmine::YamlConfigParser.new('some_path', 'some_project_root', nil, yaml_loader)
+ parser.spec_helper.should == 'some_project_root/some_spec_helper.rb'
+ end
+
it "spec_dir uses default path when spec dir is blank" do
yaml_loader = lambda do |path|
if path == "some_path"
Please sign in to comment.
Something went wrong with that request. Please try again.