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?
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?
Share Improve this question asked Nov 25, 2011 at 21:30 Casey ChowCasey Chow 1,8144 gold badges19 silver badges29 bronze badges2 Answers
Reset to default 5Here'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./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.
As of 2021, here's how to change the folder name when using the jasmine-browser-runner
with NodeJS.
Install jasmine and setup the project:
npm install --save-dev jasmine-browser-runner jasmine-core
npx jasmine-browser-runner init
Rename the spec
folder to test
and edit jasmine-browser.json
:
"specDir": "test"
Run the tests with this mand:
npx jasmine-browser-runner runSpecs --config=test/support/jasmine-browser.json