Skip to content

Commit

Permalink
Load jasmine_helper after configuring from yaml
Browse files Browse the repository at this point in the history
- 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
ragaskar committed Jan 11, 2013
1 parent 478c602 commit 63e8d46
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions generators/jasmine/jasmine_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions generators/jasmine/templates/spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Original file line number Diff line number Diff line change
@@ -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
#

Original file line number Diff line number Diff line change
@@ -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
#

1 change: 1 addition & 0 deletions lib/jasmine/command_line_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion lib/jasmine/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/jasmine/yaml_config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions spec/yaml_config_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 63e8d46

Please sign in to comment.