How can I customize Jasmine's directory structure?

When using the Jasmine Rubygem, I find it extremely annoying that I have to conform to the generated directory structure which has a javascripts subfolder within the spec folder. I find it useless since I'm writing entirely in Javascript.

I find I can change this within the public folder by changing the generated jasmine.yml, however, this is not what I wanted since I still have to keep the javascripts folder with me.

Is there any way of customizing this folder structure?


Solution 1:

Here's how I did this with jasmine gem 1.0.2.1:

1) Customize the jasmine_config.rb file to override the simple_config_file method to point to the correct yml file path. This file is initially generated at spec/javascripts/support/jasmine_config.rb. As seen on the github source (https://github.com/pivotal/jasmine-gem/blob/v1.0.2.1/lib/jasmine/config.rb), the method is hardcoded to use:

def simple_config_file
  File.join(project_root, 'spec/javascripts/support/jasmine.yml')
end

I wanted to rename my 'spec' directory to 'test' so the top of my jasmine_config.rb file looks like this:

module Jasmine
  class Config
    def simple_config_file
      File.join(project_root, 'test/javascripts/support/jasmine.yml')
    end
  end
end

2) Force rake to load the config file. I did this by adding the line:

require 'test/javascripts/support/jasmine_config.rb'

immediately after requiring jasmine in my Rakefile.

3) Update jasmine.yml (also in the support folder) to indicate where your javascript test files live. My yml file now ends with this:

# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: test/javascripts

Of course, you need to adjust that path "test" to be what you want.

I think this approach should work with the latest version of the gem, but this approach will break in the future if they change the interface of that Config class.